Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mistake in perlipc doc, perl 5.10.0 #9333

Closed
p5pRT opened this issue May 18, 2008 · 7 comments
Closed

Mistake in perlipc doc, perl 5.10.0 #9333

p5pRT opened this issue May 18, 2008 · 7 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented May 18, 2008

Migrated from rt.perl.org#54412 (status was 'resolved')

Searchable as RT54412$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented May 18, 2008

From andrew@sundale.net

Created by andrew@sundale.net

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

Perl Info

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

@p5pRT
Copy link
Author

@p5pRT p5pRT commented May 19, 2008

From @smpeters

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

@p5pRT
Copy link
Author

@p5pRT p5pRT commented May 19, 2008

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 18, 2018

From zefram@fysh.org

Fixed in commit 6fc8325.

-zefram

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 18, 2018

@iabyn - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jun 23, 2018

From @khwilliamson

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.

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jun 23, 2018

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant