Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm on an Ubuntu 10.04 box, and started a server in the background (myserver &) over ssh. It's been running fine, but I need a way to get at the server's stdin, as the only way to control the server is through this method.

Is there some way to get at the stdin of an already-running process so I can write to it (and hopefully read its stdout)? Obviously, if I were going to be doing this now, I'd start it with a FIFO redirecting to stdin, but unfortunately it's a little late for that now.

Any ideas?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

You could try writing to it's /proc pid directory. Say your daemons' pid is 2000, try writing to /proc/2000/fd/0

share|improve this answer
    
Thanks... I found that right after I posted this (after a day of looking--typical). That seems to work (as far as actually sending data to the program). Unfortunately, the program doesn't accept the commands. I tested it running the server on my local computer, and sure enough, I see the data appear, but the program doesn't recognize the commands. I have to manually press enter on the server terminal, and then it just says unrecognized command. Maybe some java weirdness? I'm stuck... –  tajmorton Oct 8 '10 at 9:35
    
how about echo -e "something\n" > /proc/2000/fd/0? –  katriel Oct 8 '10 at 9:39

You could start you server with a named pipe (fifo) as its input:

mkfifo /tmp/srv-input
cat > /tmp/srv-input &
echo $! > /tmp/srv-input-cat-pid
cat /tmp/srv-input | myserver &

The cat > /tmp/srv-input & is important to avoid your server to receive a EOF. At least one process must have the fifo opened in writing so your server does not receive a EOF. The PID if this command is saved in the /tmp/srv-input-cat-pid file for latter kill.

And then do something like bellow to send input to your server:

echo "command" > /tmp/srv-input

To send a EOF to your server, you need to kill the cat > /tmp/srv-input process which PID has been saved in the /tmp/srv-input-cat-pid file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.