Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So I had some PHP scripts running from the command line, and wanted to stop them running.

I ran

$ ps aux | grep php
$ sudo kill 8754
$ sudo kill 8767

And then ran

$ ps aux | grep php

again to check the processes had terminated but got this kind of output:

jon      8754  0.4 53.5 3044256 2205204 ?     T    10:34   0:15 php awesome_script.php
jon      8767  0.4 53.5 3044256 2205204 ?     T    10:34   0:15 php awesome_script.php
jon     12275  0.0  0.0   4156   892 pts/1    S+   11:27   0:00 grep --color=auto php

I looked up what the T meant in the state column and discovered that it means Stopped, but I don't understand what that means the process is doing.

I know you can create your own signal handling in PHP, but I've not done that, so when PHP receives a SIGTERM signal what does it do?

What is a stopped process doing (if anything)?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

It means the process has received a STOP signal, and won't do anything much until it receives a CONT signal, not even terminate.

The most common source of STOP signals is the user hitting ^z while the process is in the foreground, and the common way to send a CONT afterwards is typing fg or bg which continue the process in the foreground and background respectively.

Another way to send STOP to a process is kill -STOP $pid. Similarly, CONT can be sent to a process with kill -CONT $pid.

Since you sent TERM signals to the processes, I assume you want them to terminate. For that to happen, the processes must receive CONT signals. You can send those by typing kill -CONT 8754 8767 in a terminal window.

share|improve this answer
    
Would sending a CONT signal allow the script to run until it had completed? Or would it cause the script to terminate immediately? –  Jon Mar 21 '12 at 14:26
    
The process continues what it was doing (before STOP) upon receiving a CONT. If you sent a TERM (by kill $pid for example) while it was stopped, however, it will then (belatedly) respond to that TERM and terminate. –  Eroen Mar 21 '12 at 14:48
    
Hmm, so I sent a TERM by running kill 8754 which should cause the process to eventually terminate right? Do you know which state a process would be in while it's getting round to terminating? Given that the process entered the STOP state, as if it had received a STOP signal from kill -STOP 8754, could that also happen if it was sent a TERM signal? –  Jon Mar 21 '12 at 16:28
    
A stopped process will not terminate due to a TERM signal until it is continued. It will terminate immediately if it receives a KILL signal, even while stopped. I assume a process will be in Run state when it terminates. I'm not very familiar with PHP, and don't know how to tell why a process stopped, sorry. Generally, though, processes don't stop but terminate when they receive TERM. –  Eroen Mar 21 '12 at 16:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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