开发者

Cannot run background process on Amazon Linux Instance, but runs on MAC OS X

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

I'm trying to run a php script thru cmd line. It runs fine on Amazon Linux, if I dont append & character at the end. If i append &, it is having a T as its STAT

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 arg开发者_C百科1 arg2 arg3
Prints some output...
Prints some output...
Prints some output...
Prints some output...
Done...
[root@someIp somePath]#

Same situation: https://forums.aws.amazon.com/thread.jspa?messageID=281552

Thanks!


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:

# php /path/to/myPhpScript.php arg1 arg2 arg3 0</dev/null 1 >/dev/null 2>log.txt &

OR

# php /path/to/myPhpScript.php arg1 arg2 arg3 </dev/null >/dev/null 2>log.txt &

Thanks! :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜