douling1936
douling1936
2011-05-13 22:21

如何使用shell_exec从其路径中查找进程ID

已采纳

I need to provide my users with a way to stop their cron task so that it can restart on its 5 minute cycle.

I think I need to use shell_exec to get the processes back and then kill the specific process. The only way I will be able to distinguish this process from the others running on the server are the paths i.e php /home/sconmod/public_html/**URN**/Includes/System/CronTask.php.

Does anyone know a way I can get the process ID of a process by matching the path?

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douse8732 douse8732 10年前

    The usual way of dealing with this problem is a PID file. Write the cron job's process ID to a file in a known location when the job starts and delete the file when the job ends. If you need to kill the process before it ends, just read the PID out of the file and kill the process. You'll want to include some signal handling in the cron jobs so that they properly clean up their PID files though, you wouldn't want to send a SIGTERM to the wrong process just because someone left a stale PID file around.

    点赞 评论 复制链接分享