如何使用 shell_exec 从其路径查找进程 ID
我需要为我的用户提供一种停止其 cron 任务的方法,以便它可以以 5 分钟为周期重新启动。
我想我需要使用 shell_exec 来恢复进程,然后终止特定进程。我能够将该进程与服务器上运行的其他进程区分开来的唯一方法是路径,即 php /home/sconmod/public_html/**URN**/Includes/System/CronTask.php 。
有谁知道如何通过匹配路径来获取进程的进程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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
处理这个问题的通常方法是使用PID文件。当作业启动时,将 cron 作业的进程 ID 写入已知位置的文件,并在作业结束时删除该文件。如果您需要在进程结束之前终止该进程,只需从文件中读取 PID 并终止该进程即可。您需要在 cron 作业中包含一些信号处理,以便它们正确清理 PID 文件,但您不会希望仅仅因为有人留下了陈旧的 PID 文件而将 SIGTERM 发送到错误的进程。
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.