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
  • 34,649
  • 32
  • 119
  • 183
user3346931
  • 305
  • 1
  • 3
  • 10
  • 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
  • See [How can I disown a running process and associate it to a new screen shell?](http://unix.stackexchange.com/q/4034/15241) – jofel Jun 29 '15 at 15:00
  • 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

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
John
  • 16,759
  • 1
  • 34
  • 43
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,424
  • 3
  • 27
  • 50