I have a python program that outputs to stdout and a log file.

However, the person I am making this for wants to know if I can set it up so that he can see the output of the file, while it is running on a different terminal or in the background. For example the program launched at startup, and he wants to ssh into it and see the output it is running.

So is there a way to see the output of a process that is currently running?

Preferably in bash or python, if possible.

  • 1
    If it ouputs into a log file, he could do a tail -f file.log? – fredtantini Jun 29 '15 at 13:56
  • I agree with @fredtantini, I use tail to watch a certain file, but I also use watch if I know there are multiple files in that folder that I want to keep an eye on. – Kevdog777 Jun 29 '15 at 14:05
  • Problem with that screen is that requires keyboard input from my understanding, which is something I can't do as the program is meant to go on a headless server. – user3346931 Jun 29 '15 at 15:53

I see two options. One, he can use tail -f to see the log file as it's being written, or two, he can have the program start inside a screen (or similar) session to which he can (re-)attach later.

If he doesn't know the location of the log file, he can use top, ps or a similar tool to find the process ID, then run lsof -p1234 where 1234 is the process id to list the open files of that process.

| improve this answer | |

I personally prefer using less to do this same thing.

less your_file

After starting less, the F command (not a command line flag) will begin to actively monitor the end of the file. While watching the end of the file in this mode CTRL-c will stop appending output to less and allow you to page around. Very handy.

| improve this answer | |

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.