Create zombie intentionally?

I

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!

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;
};
 
B

Ben Morrow

Quoth "Ishmael said:
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
 
C

comp.llang.perl.moderated

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}'
 
X

xhoster

Ishmael said:
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
 
D

Darren Dunham

Ishmael said:
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.
 
B

Bart Lateur

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;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top