2

我的 crontab 配置如下:

*/2 * * * * php /home/ec2-user/myapp/myscript.php >> /home/ec2-user/myapp/log/myapp.log 2>&1

当我执行 ps aux 时,我看到以下输出:

ec2-user  1296  0.0  0.0   2984   992 ?        Ss   15:36   0:00 /bin/sh -c /home/ec2-user/myapp/myscript.php >> /home/ec2-user/myapp/log/myapp.log 2>&1 SHELL=/bin/sh HOME=/home/ec2-user PATH=/usr/bin:/bin LOGNAME=ec2-user USER=ec2-user
ec2-user  1299  0.3  3.7  91528 63612 ?        S    15:36   0:16 /home/ec2-user/myapp/myscript.php SHELL=/bin/sh USER=ec2-user PATH=/usr/bin:/bin PWD=/home/ec2-user SHLVL=1 HOME=/home/ec2-user LOGNAME=ec2-user _=/usr/bin/php

对我来说,看起来同一个进程同时启动了两次,进程 1 的 PID 为 1296,进程 2 的 PID 为 1299。

这正常吗?为什么 ps 输出中有两个进程而不是一个?

4

2 回答 2

7

It looks like /bin/sh is used to invoke your cron tabs, so that they run in their own environment, that's the first process. Then /bin/sh invokes php to run your actual script, and php is your second process. There's nothing wrong with this.

于 2012-08-08T18:13:39.413 回答
4

尝试在php之前添加exec

*/2 * * * * exec /usr/bin/php /home/ec2-user/myapp/myscript.php >> /home/ec2-user/myapp/log/myapp.log 2>&1

shell 进程 /bin/sh 将被 exec 替换

于 2013-08-25T10:31:36.273 回答