How to get stdout of a "lost" session
I don't well what's the name of the situation, I think yesterday I closed a session with a background ipython process, but I am still able to connect to it (the process is running a web server and I can load the page). Can I still get to see the stdout/stderr of the process?
If I run ps -f -Umyname
I get (I deleted some unrelated lines, but the PID and PPID are the real ones):
UID PID PPID C STIME TTY STAT TIME CMD
16131 1767 1765 0 11:20 ? S 0:03 sshd: myname@notty
16131 1946 21019 0 11:25 ? Sl 1:47 /usr/bin/python -m IPython.kernel -f /home/myname/.ipython/profile_default/security/kernel-c72091
16131 3946 21019 0 14:37 pts/3 Ss+ 0:00 /bin/bash
16131 4003 4001 0 14:38 ? S 0:01 sshd: myname@pts/14
16131 4004 4003 0 14:38 pts/14 Ss 0:00 -bash
16131 6366 4004 0 16:41 pts/14 R+ 0:00 ps -f Umyname
16131 21019 1 0 Jul30 ? Sl 0:52 /usr/bin/python ipython notebook
I am sure it's not being ran inside a screen. Any idea? I am interest in PID 21019
Solution 1:
You can use strace
to see the output of a running process.
$ strace -p 21019 -e write=1,2
The above command will attach to the process with PID 21019 and trace write-calls to fd 1 (stdout) and 2 (stderr).
When you're done, you can send a sigint
(to strace) to detach (press ctrl + c).
edit: There are also some tools that allow you to attach a running process to a new terminal, e.g. reptyr, screenify, retty. Note that most of these use strace, gdb or similar trace-tools to accomplish this, but they tend to produce prettier output.