I want to give my program the ability to fork off a child at will. So I have a sub that forks when
you call it. but it seems that, unlike when I use the standard child then parent in an if/else statement,
when the parent in the code dies the kids do not go with it. I can write a clean up routine (will
do that either way I imagine), but would like to understand why this is the case or if I'm doing
something grossly wrong and it's a result of that =) code for those who havn't stopped reading this
yet (this is still just a prototype):
#!/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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.