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...
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.
Well, landed on a solution: I switched back to
proc_open()
instead ofpopen()
. Then it's as simple as:Just send a kill (or abort) signal using kill function: