douling1936 2011-05-13 22:21
浏览 170
已采纳

如何使用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 2011-05-13 23:08
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?