I have a little PHP page which I want to launch a somewhat long lived program
on the server. The server program is written in perl and returns some output
to the PHP page which is used to give the user a little feedback.
The Perl program appears to be doing all the right things - I don't wait for
my child with $SIG{CHLD} = 'IGNORE' and I have autoflushing set on with
$| = 1 and sure enough, when I run the program from a terminal (with the
exact same command line as PHP uses with system() ) it takes a couple of
seconds to run, returns the correct output, and ends and ps then shows it's
abandoned child still running with a parent of 1 just as it should.
Yet when I do this from the PHP page, PHP doesn't finish until both parent and
child have finished.
When I deliberately delay the parent's death a little and run the perl program
from the command line, I see just what I'd expect to see in a ps listing -
two copies of the perl program, parent and child. When the parent dies, the
child is adopted by init, just as I expect.
However, when I run it from php it's a little different. I see both processes
running, but when the parent SHOULD end it stays in the process list showing
<defunct> until such time as its child dies, yet while it's showing <defunct>
its child is showing a PPID of 1 so it has been adopted by init as expected.
However, for some reason it won't die until its child does, which of course is
somewhat defeating the point of having the blooming thing fork in the first
place. Any ideas?
--
Niall
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!