Skip Menu |
Report information
Id: 54412
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: andrew [at] sundale.net
Cc:
AdminCc:

Operating System: Linux
PatchStatus: (no value)
Severity: medium
Type: docs
Perl Version: 5.8.5
Fixed In: 5.27.8



CC: andrew [...] sundale.net
Subject: Mistake in perlipc doc, perl 5.10.0
Date: Mon, 19 May 2008 03:49:08 +0400
To: perlbug [...] perl.org
From: andre [...] sundale.net
Download (untitled) / with headers
text/plain 5.9k
This is a bug report for perl from andrew@sundale.net, generated with the help of perlbug 1.35 running under perl v5.8.5. ----------------------------------------------------------------- [Please enter your report here] 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 [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=docs severity=medium --- This perlbug was built using Perl v5.8.5 in the Red Hat build system. It is being executed now by Perl v5.8.5 - Tue Mar 15 06:44:40 EST 2005. Site configuration information for perl v5.8.5: Configured by Red Hat, Inc. at Tue Mar 15 06:44:40 EST 2005. Summary of my perl5 (revision 5 version 8 subversion 5) configuration: Platform: osname=linux, osvers=2.4.27rimu1-3um, archname=i386-linux-thread-multi uname='linux rhel4.rimuhosting.com 2.4.27rimu1-3um #1 thu sep 9 02:48:08 utc 2004 i686 i686 i386 gnulinux ' config_args='-des -Doptimize=-O2 -mcpu=i386 -march=i686 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm', optimize='-O2 -mcpu=i386 -march=i686', cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm' ccversion='', gccversion='3.4.3 20041212 (Red Hat 3.4.3-9.EL4)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.3.4.so, so=so, useshrplib=true, libperl=libperl.so gnulibc_version='2.3.4' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: --- @INC for perl v5.8.5: /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/perl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl . --- Environment for perl v5.8.5: HOME=/home/andre LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/java/jdk/bin:/usr/kerberos/bin:/usr/java/jdk/bin:/usr/lib/courier-imap/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin PERL_BADLANG (unset) SHELL=/bin/sh
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 2.1k
Show quoted text
> 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. Hangup
To: perl5-porters [...] perl.org
From: Zefram <zefram [...] fysh.org>
Date: Thu, 18 Jan 2018 03:12:33 +0000
Subject: Re: [perl #54412] Mistake in perlipc doc, perl 5.10.0
Fixed in commit 6fc8325ded66d545bdfa5afbeb29926b9e0680d5. -zefram
Download (untitled) / with headers
text/plain 317b
Thank you for filing this report. You have helped make Perl better. With the release yesterday of Perl 5.28.0, this and 185 other issues have been resolved. Perl 5.28.0 may be downloaded via: https://metacpan.org/release/XSAWYERX/perl-5.28.0 If you find that the problem persists, feel free to reopen this ticket.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org