-1

I have a python script script.py. I decide to execute this in the Terminal.

python script.py

It has been running for several hours. How do I check the status? How can I check whether this program is still responsive?

top doesn't work in this case, as the program is still running. I think there's a keyboard command---i't's something like 'Control' + 'something'

ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
  • 2
    can't you print from your script itself, that what it is currently doing! – praba230890 Jun 12 '16 at 14:51
  • Well what's it doing? Could you add `logging`? – jonrsharpe Jun 12 '16 at 15:01
  • @praba230890 There is a keyboard command which allows you to see for how long the process has been running. This is the preferred option. – ShanZhengYang Jun 12 '16 at 15:04
  • @jonrsharpe Running the script. That Terminal window is inaccessible as long as the script hasn't completed. – ShanZhengYang Jun 12 '16 at 15:05
  • No, I mean *what is the script doing?* – jonrsharpe Jun 12 '16 at 15:05
  • @ShanZhengYang You can suspend a process with `` than continue it as a background process with `bg`. – Andreas Louv Jun 12 '16 at 15:07
  • @jonrsharpe Nothing special. I'm manipulating about 15 GB of data frames and outputting to other files. For this command, it doesn't matter what the script is doing, I believe. – ShanZhengYang Jun 12 '16 at 15:09
  • @andlrc After suspending/stopping the script, how do I "un-suspend it"? Doesn't `bg` restart the program? – ShanZhengYang Jun 12 '16 at 15:10
  • Well then how many of the files you expected in output have turned up? That would give you some idea of the progress, surely? – jonrsharpe Jun 12 '16 at 15:11
  • @ShanZhengYang The process is not stopped just suspended. Typing `jobs` will give info about processes connected to your shell. You can bring a suspended process to the background with `bg` and foreground with `fg`. – Andreas Louv Jun 12 '16 at 15:11
  • 1
    You can monitor the process system calls with `strace`. Get its PID and then do `sudo strace -p ` (and optionally add `-o tracefile.txt` to send the trace to a file). This may dump a lot of data to just run it for a short "peek" at what's going on. – tdelaney Jun 12 '16 at 15:15

1 Answers1

4

While your program is still running type C-z (while pressing 'Ctrl' press 'z') You wille get a output like this:

[1]  + 2267 suspended  

python script.py

Then you can get the current runtime with:

ps -p "2267" -o etime

Replace "2267" with the pid shown in step 1. When you want to resume your script type:

fg %1

You can think of %1 as the current count of "backgrounded" processes. If the output after C-z shows something e.g. [4] + XXXX suspended means that you must use fg %4 to resume the process.

cb0
  • 8,415
  • 9
  • 52
  • 80
  • When using this command to output the ELAPSED runtime: ps -p "PID_NUMBER" -o etime Is it possible to program this command to output a time every 5-10 minutes? That is, without user input? – ShanZhengYang Jun 12 '16 at 15:41
  • 1
    @ShanZhengYang `while ps -p pid -o etime; do sleep 300; done` – Andreas Louv Jun 12 '16 at 15:53