Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Parent process finished. How to exit the child process.

by spazm (Monk)
on May 07, 2010 at 04:29 UTC ( #838853=note: print w/replies, xml ) Need Help??

in reply to Parent process finished. How to exit the child process.

Some options:
  1. parent sends kill signal to child when parent processing is complete. Child dies. parent reaps child and exits (or continues, I suppose).
  2. reverse the roll of parent and child. The child does the computing and the parent handles the counting&display. Child exits when complete and parent reaps child via SIG CHLD handler.
if(my $pid=fork){ while(my $c = ReadKey){ #doing something... ; } kill( HUP => $pid ); wait(0); } else { my $count = 0; while(1){ sleep(1); print $count++; } }
if(my $pid=fork){ #parent my $run = 1; $SIG{CHLD} = sub { $deadchildpid = wait; $run = 0 }; my $count = 0; while($run){ sleep(1); print $count++; } } else { #child while(my $c = ReadKey){ #doing something... ; } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://838853]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-12-14 13:49 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (394 votes). Check out past polls.