1

I have a process running on a Linux machine that I would like to access the output from. It's in it's own container that I'm using docker exec to su into. With ps I can see:

UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 18:45 ?        00:00:00 python ./manage.py runserver

I thought I could do this with

fg 1

but that did not work. How can I capture the output of this already running process?

  • NEVER run the django (or any other framework's) dev server as root! – ThiefMaster Mar 28 '17 at 22:13
  • Its output should be going to standard out. You can see what this is attached to with ls -l /prod/1/fd, but it's entirely likely these will be bound to /dev/null, in which case the output is, put simply, gone. – DopeGhoti Mar 28 '17 at 22:13
  • You get the output in whatever terminal you started it in. Or did you close it? If yes, just kill the process and start it in a new terminal. – ThiefMaster Mar 28 '17 at 22:13
  • How in the world would python be PID 1 anyhow? – DopeGhoti Mar 28 '17 at 22:14
  • @ThiefMaster It's in it's own container that I'm using docker exec to su into. – wogsland Mar 28 '17 at 22:18
3

Use docker logs <yourcontainer> on the host to read its stdout. Add --follow to keep the output going.

0

You can only fg a job (or process) which you have run on the current terminal and either suspended (e. g. with Ctrl+Z) and/or sent to run in the background (e. g. with bg). Chances are exceedingly unlikely that PID 1 is on the current terminal; it is usually binding its standard input, output, and error streams to /dev/null. You can check with:

$ sudo ls -l /proc/1/fd/{0,1,2}
lrwx------ 1 root root 64 Mar 28 15:13 /proc/1/fd/0 -> /dev/null
lrwx------ 1 root root 64 Mar 28 15:13 /proc/1/fd/1 -> /dev/null
lrwx------ 1 root root 64 Mar 28 15:13 /proc/1/fd/2 -> /dev/null

You can only check on the file descriptors for processes which you own, which is why sudo is needed here. The roles of these descriptors are as follows for any process:

  • fd/0 - Standard input
  • fd/1 - Standard output
  • fd/2 - Standard error
  • Sadly I don't have sudo. I updated the question with some more detail. – wogsland Mar 28 '17 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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