Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a script I'm trying to launch with

php ./Script.php &

The task goes into the background but it is stopped. When I try to run it with bg it simply stays stopped.

$ jobs
[1]+  Stopped                 php ./Script.php
$ bg
[1]+ php ./Script.php &

[1]+  Stopped                 php ./Script.php
$

ps shows the job state as T

$ ps ax | grep Script
951 pts/5    T      0:00 php ./Script.php

cat /proc/PID/wchan shows "pipe_wait"

Update:

This happens with any PHP script, even <?php sleep(1000);

Update:

Thanks for all the great answers and comments. I understand why this is happening on a technical level now, but I'm not sure what about some versions of PHP are causing this. But, that is not a *nix question.

share|improve this question
1  
What is this script doing? Likely cause is that it tried to read from STDIN and was sent a SIGTTIN. –  Patrick Aug 28 at 0:21
    
The script does read command line arguments from argv. Is that not possible to do with a background job? –  chugadie Aug 28 at 0:27
    
I am able to background with nohup. But I've never run into such a situation before (that I can recall). –  chugadie Aug 28 at 0:33

2 Answers 2

up vote 5 down vote accepted

Almost certainly the command tried to read from the terminal when it was not in the foreground process group. This will cause the kernel to send SIGTTIN to the process, which by default will stop the process. A simple test would be to redirect stdin to /dev/null. If the process runs in the background without being stopped then the problem was SIGTTIN as described.

share|improve this answer
    
Redirecting /dev/null to stdin and running with nohup both allow the program to be backgrounded. Why would nohup conceal or dismiss a SIGTTIN? –  chugadie Aug 28 at 13:45

If NO terminal (or stdin) input is truely required, then you can do the following:

 php ./Script.php </dev/null &
share|improve this answer

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.