1

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.

Faheem Mitha
  • 35,108

2 Answers2

3

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.

John
  • 17,011
1

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.

111---
  • 4,516
  • 3
  • 30
  • 52