> man perlipc states that: > "Sending a signal to a negative process ID means that you send the > signal to > the entire Unix process-group." > and the example follows: > "{ > local $SIG{HUP} = 'IGNORE'; > kill HUP => -$$; > # snazzy writing of: kill('HUP', -$$) > }" > > According to > http://www.opengroup.org/onlinepubs/009695399/functions/kill.html > "int kill(pid_t pid, int sig); > [...] > If pid is negative, but not -1, sig shall be sent to all processes > (excluding an unspecified set of system processes) whose process group > ID is > equal to the absolute value of pid,". > > The problem is that variable $$ contains the current process pid, > which is equal to "process group ID" ONLY for process group leader. > > Example: > -sh-3.00$ uname -a > Linux somehost.net 2.6.16.33-xenU #2 SMP Fri Jan 11 00:07:17 UTC 2008 > i686 > athlon > i386 GNU/Linux > -sh-3.00$ cat p.pl > #!/usr/bin/perl > > print "Cur pid: $$\n"; > my $pgrpid = getpgrp(); > print "Cur PGID: $pgrpid\n"; > > print "Trying to kill cur pid-based pgrpid.\n"; > kill('HUP', -$$); > sleep(1); > > print "Trying to kill right pgrpid.\n"; > kill('HUP', -$pgrpid); > > sleep(1); > print "Successfully exited.\n"; > > > #p.pl is a process group leader now - it works > -sh-3.00$ ./p.pl > Cur pid: 1286 > Cur PGID: 1286 > Trying to kill cur pid-based pgrpid. > Hangup > > #p.pl NOT a leader now - the $$-based code does not work. > -sh-3.00$ echo test|./p.pl > Cur pid: 1288 > Cur PGID: 1287 > Trying to kill cur pid-based pgrpid. > Trying to kill right pgrpid. > Hangup > I made a slight change to the script below. #!/usr/bin/perl print "Cur pid: $$\n"; my $pgrpid = getpgrp(); print "Cur PGID: $pgrpid\n"; print "Trying to kill cur pid-based pgrpid.\n"; kill('HUP', -$$) || warn $!; # <--warning sleep(1); print "Trying to kill right pgrpid.\n"; kill('HUP', -$pgrpid) || warn $!; # <--warning sleep(1); print "Successfully exited.\n"; ...pops up a warning. steve@picard:~$ echo test | ./p.pl Cur pid: 23680 Cur PGID: 23679 Trying to kill cur pid-based pgrpid. No such process at ./p.pl line 8. Trying to kill right pgrpid. HangupThread Previous