杀死用 popen() 打开的进程?
我正在使用 popen() 打开一个长时间运行的进程。为了调试,我想在进程完成之前终止它。调用 pclose() 只会阻塞,直到子进程完成为止。
我怎样才能杀死该进程?我没有看到任何简单的方法可以从 popen() 返回的资源中获取 pid,以便我可以向它发送信号。
我想我可以做一些杂乱的事情,并尝试使用某种命令行黑客技术将 pid 混入输出中......
I'm opening a long-running process with popen(). For debugging, I'd like to terminate the process before it has completed. Calling pclose() just blocks until the child completes.
How can I kill the process? I don't see any easy way to get the pid out of the resource that popen() returns so that I can send it a signal.
I suppose I could do something kludgey and try to fudge the pid into the output using some sort of command-line hackery...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,找到了一个解决方案:我切换回
proc_open()
而不是
popen()
。那么就很简单了:Well, landed on a solution: I switched back to
proc_open()
instead ofpopen()
. Then it's as simple as:只需使用kill函数发送一个kill(或中止)信号:
Just send a kill (or abort) signal using kill function:
您可以找到 pid,并通过执行以下操作检查您是否确实是其父级:
它在 fast-cgi PHP 服务器上运行得很好。
You can find the pid, and checks that you're really its parent by doing:
It's working quite well on a fast-cgi PHP server.