Create zombie intentionally?

Discussion in 'Perl Misc' started by Ishmael, Mar 8, 2007.

  1. Ishmael

    Ishmael Guest

    Ok, this may sound odd, but I would like to create a zombie process
    intentionally. I've been reading the perldoc for perlipc and it seems
    like an unhappy marriage between 'alarm' and 'system' should do the
    trick, but I haven't been able to get it to work. Can someone give me
    a simple (!) example of how to create a zombie (using the alarm/
    system combo - or even better, using fork and exec)? Thanks for you
    help!

    By the way, here's what I've been trying (unsuccessfully):

    eval {
    local $SIG{ALRM} = sub {die "system call killed by alarm"};
    alarm 1;
    my $cmd = 'perl -e \'while(1) { print "bla\n"; sleep(1); }\'';
    # my $cmd = "/bin/tcsh\nwhile 1\necho \"bla\\n\"\nend\n";
    print $cmd, "\n";
    system($cmd);
    alarm 0;
    };
     
    Ishmael, Mar 8, 2007
    #1
    1. Advertising

  2. Ishmael

    Ben Morrow Guest

    Quoth "Ishmael" <>:
    > Ok, this may sound odd, but I would like to create a zombie process
    > intentionally. I've been reading the perldoc for perlipc and it seems
    > like an unhappy marriage between 'alarm' and 'system' should do the
    > trick, but I haven't been able to get it to work. Can someone give me
    > a simple (!) example of how to create a zombie (using the alarm/
    > system combo - or even better, using fork and exec)? Thanks for you
    > help!


    use POSIX qw/_exit/;

    $SIG{CHLD} = 'DEFAULT';
    # just to make sure. the important thing is that is shouldn't be
    # 'IGNORE', or zombies may be automatically reaped.

    my $kid = fork;
    defined $kid or die "fork failed: $!";
    $kid or _exit 0;

    # now be careful with wait/waitpid

    Ben

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    'Alcestis') [ flame, and falls out of sight. ]
     
    Ben Morrow, Mar 8, 2007
    #2
    1. Advertising

  3. On Mar 7, 6:55 pm, "Ishmael" <> wrote:
    > Ok, this may sound odd, but I would like to create a zombie process
    > intentionally. I've been reading the perldoc for perlipc and it seems
    > like an unhappy marriage between 'alarm' and 'system' should do the
    > trick, but I haven't been able to get it to work. Can someone give me
    > a simple (!) example of how to create a zombie (using the alarm/
    > system combo - or even better, using fork and exec)? Thanks for you
    > help!
    >
    > By the way, here's what I've been trying (unsuccessfully):
    >
    > eval {
    > local $SIG{ALRM} = sub {die "system call killed by alarm"};
    > alarm 1;
    > my $cmd = 'perl -e \'while(1) { print "bla\n"; sleep(1); }\'';
    > # my $cmd = "/bin/tcsh\nwhile 1\necho \"bla\\n\"\nend\n";
    > print $cmd, "\n";
    > system($cmd);
    > alarm 0;
    >
    > };


    quick, dirty, and an expensive 10 sec. shelf life...
    but you can kill the abusive parent ASAP and give the
    child a decent burial...


    perl -le 'if (fork){print $$; 1 while time()-$^T <10} else {exit}'


    --
    Charles DeRykus
     
    comp.llang.perl.moderated, Mar 8, 2007
    #3
  4. Ishmael

    Guest

    "Ishmael" <> wrote:
    > Ok, this may sound odd, but I would like to create a zombie process
    > intentionally. I've been reading the perldoc for perlipc and it seems
    > like an unhappy marriage between 'alarm' and 'system' should do the
    > trick, but I haven't been able to get it to work. Can someone give me
    > a simple (!) example of how to create a zombie (using the alarm/
    > system combo - or even better, using fork and exec)? Thanks for you
    > help!


    fork or exit; # no error checking done.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Mar 8, 2007
    #4
  5. Ishmael <> wrote:
    > Ok, this may sound odd, but I would like to create a zombie process
    > intentionally. I've been reading the perldoc for perlipc and it seems
    > like an unhappy marriage between 'alarm' and 'system' should do the
    > trick, but I haven't been able to get it to work. Can someone give me
    > a simple (!) example of how to create a zombie (using the alarm/
    > system combo - or even better, using fork and exec)? Thanks for you
    > help!


    It seems to me like you're overthinking it. Do you understand what a
    zombie is?

    A zombie is a child that has exited, but the parent has not called
    wait() for it.

    So you simply need to fork a child, have the child exit, and have the
    parent continue to live.

    As soon as the parent exits or calls wait(), the child should be reaped.


    > By the way, here's what I've been trying (unsuccessfully):


    > eval {
    > local $SIG{ALRM} = sub {die "system call killed by alarm"};
    > alarm 1;
    > my $cmd = 'perl -e \'while(1) { print "bla\n"; sleep(1); }\'';
    > # my $cmd = "/bin/tcsh\nwhile 1\necho \"bla\\n\"\nend\n";
    > print $cmd, "\n";
    > system($cmd);
    > alarm 0;
    > };


    system() will always wait for the child process to exit, so it will
    never create a (long-term) zombie. You have to call fork() yourself for
    that to happen.

    --
    Darren Dunham
    Senior Technical Consultant TAOS http://www.taos.com/
    Got some Dr Pepper? San Francisco, CA bay area
    < This line left intentionally blank to confuse you. >
     
    Darren Dunham, Mar 8, 2007
    #5
  6. Ishmael

    Bart Lateur Guest

    wrote:

    >fork or exit; # no error checking done.


    Nah, both parent and child will immediately exit.

    The idea of a zombie is that the child process quits, the parent goes
    on, and doesn't "wait". So, I'd try this:

    sleep 10 if fork;

    --
    Bart.
     
    Bart Lateur, Mar 8, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    8
    Views:
    460
    Ed Morton
    Apr 10, 2004
  2. Brian
    Replies:
    1
    Views:
    327
    Keith Dart
    Dec 22, 2004
  3. Replies:
    0
    Views:
    527
  4. mechtheist
    Replies:
    2
    Views:
    1,028
  5. serge.john.swilting

    plouk zombie plouk zombie

    serge.john.swilting, Aug 19, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    206
    hudson
    Aug 20, 2003
Loading...

Share This Page