开发者

How to find a process ID from its path using shell_exec

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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜