LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cannot run background process on Amazon Linux Instance, but runs on MAC OS X (https://www.linuxquestions.org/questions/linux-newbie-8/cannot-run-background-process-on-amazon-linux-instance-but-runs-on-mac-os-x-904869/)

metalhawk 09-24-2011 11:01 PM

Cannot run background process on Amazon Linux Instance, but runs on MAC OS X
 
Hello All,
Kindly review this situation.

I cannot run a background process in Amazon Linux instance, but The same runs on Mac OS X

Following is what happens
[root@someIp somePath]# php /path/to/myPhpScript.php arg1 arg2 arg3 > /dev/null 2>log.txt &
[1] 17849

[root@someIp somePath]# jobs
[1]+ Stopped php /path/to/myPhpScript.php arg1 arg2 arg3 > /dev/null 2>log.txt

[root@someIp somePath]# bg 1
[1]+ php /path/to/myPhpScript.php arg1 arg2 arg3 > /dev/null 2>log.txt &

[1]+ Stopped php /path/to/myPhpScript.php arg1 arg2 arg3 > /dev/null 2>log.txt

[root@someIp somePath]#

--------------------
But if I run without & it completes fine.

[root@someIp somePath]# php /path/to/myPhpScript.php arg1 arg2 arg3
Prints some output...
Prints some output...
Prints some output...
Prints some output...
Done...
[root@someIp somePath]#

--------
Any Help/suggestions will be of great help.

Thank You.

metalhawk 09-24-2011 11:30 PM

I figured it out myself.

For some reason, It is being stopped becos it thinks it requires some kind of input from the keyboard.
As:
0 : Standard Input (Generally the Keyboard)
1 : Standard Output (Generally the Monitor)
2 : Standard Error

So I added the standard input to read from /dev/null.

I modified my cmd as follows:
[root@someIp somePath]# php /path/to/myPhpScript.php arg1 arg2 arg3 0</dev/null 1 >/dev/null 2>log.txt &
OR
[root@someIp somePath]# php /path/to/myPhpScript.php arg1 arg2 arg3 </dev/null >/dev/null 2>log.txt &

Thanks! :)


All times are GMT -5. The time now is 02:18 PM.