See kill and getppid. Here's a recipe:
#!/usr/bin/perl print "process $$ started\n"; if ((my $pid = fork) == 0) { my $ppid = getppid; while (1) { sleep 1; unless (kill 0, $ppid) { print "child: parent($ppid) gone, exiting.\n"; exit; } else { print "child: parent($ppid) still alive...\n"; } } } else { my $secs = int rand 20; print "parent: sleeping $secs seconds\n"; sleep $secs; } print "parent: exiting after 1 second\n"; sleep 1;
In reply to Re: Daemon: Need Child to exit if parent dies
by shmem
in thread Deamon: Need Child to exit if parent dies
by aennen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |