batkins has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to run the play command synchronously in one of my scripts. My code currently looks basically (well, exactly) like this:
exec 'play', $path unless fork();
So I'm basically trying to fork off a child and have the child execute play and then exit. It works - the file is played synchronously and the main process (a Tk app) continues without the lag evident in the asynchronous version.

The trouble is that the play processes don't seem to exit. ps lists hundreds of instances of play running. There's no effect on my CPU, because each seems to be using 0% according to the GNOME process monitor. But it's still pretty annoying.

How can I get these children to exit when they've finished?

TIA, Bill Atkins

Replies are listed 'Best First'.
Re: Weirdness with fork and exec
by Mr_Person (Hermit) on Jun 12, 2003 at 00:49 UTC
    You should either make a SIGCHLD handler, or just tell Perl to ignore SIGCHLD messages by putting $SIG{CHLD}='IGNORE'; at the top of your program.
      Many thanks! Worked like a charm!