Home > Archive > PERL Beginners > January 2006 > Forking and etc.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Michael 2006-01-20, 6:59 pm |
| I am reviewing a script an old boss of mine wrote. I think I get what
most of the code is doing with the exception of this portion dealing
with forking, setting ID and reading $SIG. Can someone comment on what
these lines are accomplishing? Thanks.
my $pid = fork;
exit if $pid;
die "Couldn't fork: $!\n" unless defined($pid);
POSIX::setsid() || die "Can't start a new session: $!\n";
my $die = 0;
if (($SIG{INT}) || ($SIG{TERM}) || ($SIG{HUP})) {
$die = 1;
}
until ($die) {...
| |
| .rhavin grobert 2006-01-23, 6:57 pm |
| # fork into two processes, parent gets
# $pid = Process_ID of Child; child gets $pid = 0
# fork returns undef if fork didnt forked.
my $pid = fork;
exit if $pid; # exits the parent, so only the child is left.
die "Couldn't fork: $!\n" unless defined($pid); # exit if fork
was unsuccessful
# child now gets its own process-group, so it's running as a
daemon, i assume
POSIX::setsid() || die "Can't start a new session: $!\n";
my $die = 0;
if (($SIG{INT}) || ($SIG{TERM}) || ($SIG{HUP})) {
# %SIG is a hash containing the references to
perl-functions
# that subclass the key-event. $SIG{TERM} =
\&schwarzenegger
# means: in case of receiving a termination-signal (eg
kill 'TERM',$process)
# invoke the subroutine called "schwarzenegger"...
# in this case, it only sets the variable $die to value
1.
$die = 1;
}
until ($die) {... # so we do something till we receive a
TERM, INT or HUP-signal
hope that helps....
-.rhavin;-)
| |
| Michael 2006-01-24, 6:56 pm |
| That helps very much. Thanks Rhavin.
|
|
|
|
|