Reputation: 10400
I was running a rake task as a separate process in my server and printing on STDOUT tracking the progress of that script.
While in the SSH connection, my internet connection reset. When I reestablished the connection to the server, I found that the process was still running. I want to listen to its STDOUT ouput. I have the process id.
How can I do that?
Upvotes: 2
Views: 532
Reputation: 1594
strace -p $pid_of_process_you_want_to_see_stdout_of 2>&1| sed -re 's%^write\(1,[[:blank:]](.*),[[:blank:]]*[0-9]+\)[[:blank:]]*=[[:blank:]]*[0-9]+%\1%g'
Stolen from here:
Upvotes: 0
Reputation: 249093
retty
should do what you want. http://pasky.or.cz/dev/retty/
Upvotes: 1
Reputation: 8932
I don't have a Linux VM handy to test this on, but you might be able to connect to the process with gdb, open(2)
a new file descriptor to use as standard output, then dup2(2)
that to fd 1.
Upvotes: 0
Reputation: 107959
For the future, consider screen. This wonderful little tool can hold a large number of virtual terminals and let you easily switch from one to the next (without even using the mouse), but what's best, is if you get disconnected the virtual terminals live on until you reconnect and recover the screen session.
To start a screen session:
screen
To detach a screen session on purpose so you can disconnect and leave it running:
C-a C-d
To reattach your detached screen session
screen -dr
There's a whole lot more to it, but that's enough to get you started.
Upvotes: 1