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

SIGTERM not terminating child process #9165

Open
p5pRT opened this issue Dec 24, 2007 · 6 comments
Open

SIGTERM not terminating child process #9165

p5pRT opened this issue Dec 24, 2007 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 24, 2007

Migrated from rt.perl.org#49073 (status was 'open')

Searchable as RT49073$

@p5pRT
Copy link
Author

p5pRT commented Dec 24, 2007

From @jdhedden

This is a bug report for perl from jdhedden[at]cpan[dot]org,
generated with the help of perlbug 1.36 running under perl 5.11.0.
-----------------------------------------------------------------

'make test' in blead has been failing for me with​:

ext/Time/HiRes/t/HiRes........................................FAILED--non-zero
wait status​: 15

The cause is that SIGTERM to a child process does not always
kill it as illustrated by the test script below (also
attached)​:

  #!/usr/bin/perl

  use strict;
  use warnings;

  print("Main process = $$\n");

  my $child_pid = fork();

  if ($child_pid == 0) {
  # Child process
  print("Child process = $$\n");
  sleep(60);

  # Should not get here because child will be killed by SIGTERM
  print(">>> BUG​: Child process should have terminated\n");
  }

  sleep(2); # Let child process start

  print("Main process ($$) terminating child process ($child_pid)\n");
  kill('TERM', $child_pid);

  sleep(1);
  print("Main process done\n");

This script frequently outputs​:

  Main process = 656
  Child process = 868
  Main process (656) terminating child process (868)
  >>> BUG​: Child process should have terminated
  Main process done

This shows that the SIGTERM to the child process is knocking
it out of its sleep call, but is not terminating the
process.

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl 5.11.0:

Configured by Jerry at Mon Dec 24 08:14:26 EST 2007.

Summary of my perl5 (revision 5 version 11 subversion 0 patch 32719)
configuration:
  Platform:
    osname=cygwin, osvers=1.5.25(0.15642), archname=cygwin-thread-multi-64int
    uname='cygwin_nt-5.1 seymour 1.5.25(0.15642) 2007-12-14 19:21 i686 cygwin '
    config_args='-de -Dusedevel -Dversiononly=no -Dinstallusrbinperl
-DPERL_OLD_COPY_ON_WRITE -Duse64bitint -Dusethreads -Uusemymalloc
-Dnoextensions=attrs IPC/SysV Sys/Syslog Devel/DProf Devel/Peek re
Text/Soundex Math/BigInt/FastCalc Time/Piece -A append:ccflags=
-DPL_OP_SLAB_ALLOC -DNO_MATHOMS -A define:optimize=-Os -pipe
-funit-at-a-time -march=pentium4 -mfpmath=sse -mieee-fp -mmmx -msse
-msse2'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__
-DPL_OP_SLAB_ALLOC -DNO_MATHOMS -fno-strict-aliasing -pipe',
    optimize='-Os -pipe -funit-at-a-time -march=pentium4 -mfpmath=sse
-mieee-fp -mmmx -msse -msse2',
    cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__
-DPL_OP_SLAB_ALLOC -DNO_MATHOMS -fno-strict-aliasing -pipe'
    ccversion='', gccversion='3.4.4 (cygming special, gdc 0.12, using
dmd 0.125)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='g++', ldflags =' -Wl,--enable-auto-import
-Wl,--export-all-symbols -Wl,--stack,8388608
-Wl,--enable-auto-image-base -Wl,--enable-auto-import -s
-L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib
    libs=-ldl -lcrypt
    perllibs=-ldl -lcrypt
    libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' -s'
    cccdlflags=' ', lddlflags=' --shared  -Wl,--enable-auto-import
-Wl,--export-all-symbols -Wl,--stack,8388608
-Wl,--enable-auto-image-base -Wl,--enable-auto-import -s
-L/usr/local/lib'

Locally applied patches:
    DEVEL


@INC for perl 5.11.0:
    /usr/lib/perl5/5.11.0/cygwin
    /usr/lib/perl5/5.11.0
    .


Environment for perl 5.11.0:
    CYGWIN=ntsec
    HOME=/home/Jerry
    LANG=C
    LANGUAGE=C
    LC_ALL=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/Jerry/bin:/usr/local/src/perl/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/c/Dev-Cpp/bin/:/c/Defrag:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/Program
Files/ATI Technologies/ATI Control
Panel:/c/PROGRA~1/COMMON~1/SONICS~1:/c/Program
Files/QuickTime/QTSystem/:.
    PERLIO=perlio
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Dec 24, 2007

From @jhi

: This shows that the SIGTERM to the child process is knocking
: it out of its sleep call, but is not terminating the process.

I'm not saying that this shouldn't be made to work in Time​::HiRes,
what I am saying is that four different UNIXes (running mostly
5.8.8, one running 5.8.4) do not exhibit this behaviour, so I'm
thinking something might be funny in Cygwin.

@p5pRT
Copy link
Author

p5pRT commented Dec 24, 2007

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

@p5pRT
Copy link
Author

p5pRT commented Dec 25, 2007

From @rurban

2007/12/24, Jarkko Hietaniemi <jhi@​iki.fi>​:

: This shows that the SIGTERM to the child process is knocking
: it out of its sleep call, but is not terminating the process.

I'm not saying that this shouldn't be made to work in Time​::HiRes,
what I am saying is that four different UNIXes (running mostly
5.8.8, one running 5.8.4) do not exhibit this behaviour, so I'm
thinking something might be funny in Cygwin.

I can confirm this failing SIGTERM cygwin behaviour
but didn't dig into a fix yet.
--
Reini Urban
http​://phpwiki.org/ http​://murbreak.at/
http​://spacemovie.mur.at/ http​://helsinki.at/

@p5pRT
Copy link
Author

p5pRT commented Jun 13, 2008

From @jdhedden

Jerry D. Hedden reported​:

This shows that the SIGTERM to the child process is knocking
it out of its sleep call, but is not terminating the process.

Jarkko Hietaniemi replied​:

I'm not saying that this shouldn't be made to work in Time​::HiRes,
what I am saying is that four different UNIXes (running mostly
5.8.8, one running 5.8.4) do not exhibit this behaviour, so I'm
thinking something might be funny in Cygwin.

Reini Urban wrote​:

I can confirm this failing SIGTERM cygwin behaviour
but didn't dig into a fix yet.

Attached is a workaround for t/HiRes.t to at least keep the
Time​::HiRes test from reporting failures until the underlying
SIGTERM/sleep bug is fixed.

The workaround is to split the child's sleep in two. When the
parent sends SIGTERM, either the child will just die (basic case)
or will fall into a second short sleep (this is the workaround).
In the later case, the parent will then terminate, the child
will wake up, see that the parent has exited and will gracefully
exit as well.

@p5pRT
Copy link
Author

p5pRT commented Jun 13, 2008

From @jdhedden

--- perl-current/ext/Time/HiRes/t/HiRes.t
+++ perl-current/ext/Time/HiRes/t/HiRes.t
@​@​ -79,11 +79,14 @​@​
  if ($timer_pid == 0) { # We are the kid, set up the timer.
  my $ppid = getppid();
  print "# I am the timer process $$, sleeping for $waitfor seconds...\n";
- sleep($waitfor);
- warn "\n$0​: overall time allowed for tests (${waitfor}s) exceeded!\n";
- print "# Terminating main process $ppid...\n";
- kill('TERM', $ppid);
- print "# This is the timer process $$, over and out.\n";
+ sleep($waitfor - 2); # Workaround for perlbug #49073
+ sleep(2); # Wait for parent to exit
+ if (kill(0, $ppid)) { # Check if parent still exists
+ warn "\n$0​: overall time allowed for tests (${waitfor}s) exceeded!\n";
+ print "# Terminating main process $ppid...\n";
+ kill('TERM', $ppid);
+ print "# This is the timer process $$, over and out.\n";
+ }
  exit(0);
  } else {
  print "# The timer process $timer_pid launched, continuing testing...\n";

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

2 participants