jptxs has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; print 'do it? '; my $input = ; print 'doing it, sir', "\n"; forkin(); # make sure child is running and healthy system('ps -ef | grep fork'); # make sure parent can still function print 'if you see this all is well', "\n\n"; exit; sub forkin { my $child; die "Can't fork: $!" unless defined ($child = fork()); if ($child == 0) { # i'm the child! &dummy(); exit; } } sub dummy { # when i had only one op here, child went defunct right # after it completed sub hence the loop. I've used loops # like this before in kids and they still have always # dies with the parent... while (1) { print 'I am the child', "\n"; sleep 3; } }
"A man's maturity -- consists in having found again the seriousness one had as a child, at play." --Nietzsche
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forking through a subroutine
by merlyn (Sage) on Apr 09, 2001 at 18:09 UTC | |
by jptxs (Curate) on Apr 09, 2001 at 18:33 UTC | |
|
Re: forking through a subroutine
by premchai21 (Curate) on Apr 09, 2001 at 19:17 UTC | |
|
Re: forking through a subroutine
by daniell (Sexton) on Apr 10, 2001 at 01:28 UTC | |
by leons (Pilgrim) on Apr 10, 2001 at 12:41 UTC |