<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: perl fork() problem: child exit() kills parent in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700771#M789969</link>
    <description>Ralph,&lt;BR /&gt;&lt;BR /&gt;I send you the main part.&lt;BR /&gt;&lt;BR /&gt;I did not have a core dump!It just disapear.&lt;BR /&gt;&lt;BR /&gt;Thanks,Regards&lt;BR /&gt;Paul&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;#!/usr/contrib/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;print "&amp;gt;&amp;gt; Server Program   &amp;lt;&amp;lt;\n";&lt;BR /&gt;&lt;BR /&gt;use IO::Socket;&lt;BR /&gt;use Socket;&lt;BR /&gt;&lt;BR /&gt;my $pid;&lt;BR /&gt;my $buf;&lt;BR /&gt;my $newsock;&lt;BR /&gt;&lt;BR /&gt;$SIG{CHLD} = sub {wait () };&lt;BR /&gt;&lt;BR /&gt;my $Main_TcpSocket = new IO::Socket::INET (&lt;BR /&gt;                                            LocalHost =&amp;gt; 'hphost01.aon.nl',&lt;BR /&gt;                                            LocalPort =&amp;gt; '5000',&lt;BR /&gt;                                            Proto =&amp;gt; 'tcp',&lt;BR /&gt;                                            Listen =&amp;gt; 1,&lt;BR /&gt;                                            Reuse =&amp;gt; 1,&lt;BR /&gt;                                          ); die "Could not create socket: $!\n" unless $Main_TcpSocket;&lt;BR /&gt;&lt;BR /&gt;while ($new_sock = $Main_TcpSocket-&amp;gt;accept()) {&lt;BR /&gt;&lt;BR /&gt;    $rhost_addr = $new_sock-&amp;gt;peerhost();&lt;BR /&gt;    $rhost_port = $new_sock-&amp;gt;peerport();&lt;BR /&gt;&lt;BR /&gt;    print "\nConnection established from (rhost=$rhost_addr,rport=$rhost_port)\n";&lt;BR /&gt;&lt;BR /&gt;    $pid = fork(); die "Can not fork: $!" unless defined($pid);&lt;BR /&gt;&lt;BR /&gt;    if ($pid == 0) {&lt;BR /&gt;&lt;BR /&gt;      print "Wait for new client . . .  \n";&lt;BR /&gt;      print "- child pid='$$' created -\n";&lt;BR /&gt;&lt;BR /&gt;      while (defined ($buf = &amp;lt;$new_sock&amp;gt;)) {&lt;BR /&gt;&lt;BR /&gt;           # Doing some  stuff .......&lt;BR /&gt;           &lt;BR /&gt;      }&lt;BR /&gt;      print "- child pid='$$' closed  -\n";&lt;BR /&gt;&lt;BR /&gt;      exit(0);&lt;BR /&gt;&lt;BR /&gt;    }&lt;BR /&gt;  # ---------------------&lt;BR /&gt;  # parent process, which goes back to accept()&lt;BR /&gt;  # ---------------------&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;close ($Main_TcpSocket);&lt;BR /&gt;</description>
    <pubDate>Mon, 02 Jan 2006 10:08:48 GMT</pubDate>
    <dc:creator>Hofman P A</dc:creator>
    <dc:date>2006-01-02T10:08:48Z</dc:date>
    <item>
      <title>perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700768#M789966</link>
      <description>I have several HPUX 11.11 server with perl version 5.005_02 built for PA-RISC1.1.&lt;BR /&gt;Occasionally fork()s in order to farm out some of its tasks to a separate process. When this occurs, the parent doesn't care about the child's status or when it completes.&lt;BR /&gt;The problem is, when the child completes its work and exits, the child's exit call appears to kill the parent as well as itself.&lt;BR /&gt;&lt;BR /&gt;I got the same problem on a HPUX 11.23 server with perl version&lt;BR /&gt;v5.8.2 built for PA-RISC1.1-thread-multi.&lt;BR /&gt;&lt;BR /&gt;I tried to:&lt;BR /&gt;Exit the child by - POSIX::_exit function instead , same problem.&lt;BR /&gt;&lt;BR /&gt;Is there a solution for this problem ......&lt;BR /&gt;&lt;BR /&gt;Paul&lt;BR /&gt;--</description>
      <pubDate>Mon, 02 Jan 2006 05:42:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700768#M789966</guid>
      <dc:creator>Hofman P A</dc:creator>
      <dc:date>2006-01-02T05:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700769#M789967</link>
      <description>Does your Perl program provide a signal handler that does catch the SIGCHLD?&lt;BR /&gt;If so, what does it implement?&lt;BR /&gt;Do you get a core dump?&lt;BR /&gt;Note the warning about not re-entrant syslibs in perlipc.</description>
      <pubDate>Mon, 02 Jan 2006 09:11:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700769#M789967</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2006-01-02T09:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700770#M789968</link>
      <description>Shalom Paul,&lt;BR /&gt;&lt;BR /&gt;Different tact:&lt;BR /&gt;&lt;BR /&gt;Is either system stressed on memory use or near its limits on nproc or maxuprc.&lt;BR /&gt;&lt;BR /&gt;There may be a problem with the process table being too full.&lt;BR /&gt;&lt;BR /&gt;Good Luck,&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Mon, 02 Jan 2006 09:38:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700770#M789968</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2006-01-02T09:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700771#M789969</link>
      <description>Ralph,&lt;BR /&gt;&lt;BR /&gt;I send you the main part.&lt;BR /&gt;&lt;BR /&gt;I did not have a core dump!It just disapear.&lt;BR /&gt;&lt;BR /&gt;Thanks,Regards&lt;BR /&gt;Paul&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;#!/usr/contrib/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;print "&amp;gt;&amp;gt; Server Program   &amp;lt;&amp;lt;\n";&lt;BR /&gt;&lt;BR /&gt;use IO::Socket;&lt;BR /&gt;use Socket;&lt;BR /&gt;&lt;BR /&gt;my $pid;&lt;BR /&gt;my $buf;&lt;BR /&gt;my $newsock;&lt;BR /&gt;&lt;BR /&gt;$SIG{CHLD} = sub {wait () };&lt;BR /&gt;&lt;BR /&gt;my $Main_TcpSocket = new IO::Socket::INET (&lt;BR /&gt;                                            LocalHost =&amp;gt; 'hphost01.aon.nl',&lt;BR /&gt;                                            LocalPort =&amp;gt; '5000',&lt;BR /&gt;                                            Proto =&amp;gt; 'tcp',&lt;BR /&gt;                                            Listen =&amp;gt; 1,&lt;BR /&gt;                                            Reuse =&amp;gt; 1,&lt;BR /&gt;                                          ); die "Could not create socket: $!\n" unless $Main_TcpSocket;&lt;BR /&gt;&lt;BR /&gt;while ($new_sock = $Main_TcpSocket-&amp;gt;accept()) {&lt;BR /&gt;&lt;BR /&gt;    $rhost_addr = $new_sock-&amp;gt;peerhost();&lt;BR /&gt;    $rhost_port = $new_sock-&amp;gt;peerport();&lt;BR /&gt;&lt;BR /&gt;    print "\nConnection established from (rhost=$rhost_addr,rport=$rhost_port)\n";&lt;BR /&gt;&lt;BR /&gt;    $pid = fork(); die "Can not fork: $!" unless defined($pid);&lt;BR /&gt;&lt;BR /&gt;    if ($pid == 0) {&lt;BR /&gt;&lt;BR /&gt;      print "Wait for new client . . .  \n";&lt;BR /&gt;      print "- child pid='$$' created -\n";&lt;BR /&gt;&lt;BR /&gt;      while (defined ($buf = &amp;lt;$new_sock&amp;gt;)) {&lt;BR /&gt;&lt;BR /&gt;           # Doing some  stuff .......&lt;BR /&gt;           &lt;BR /&gt;      }&lt;BR /&gt;      print "- child pid='$$' closed  -\n";&lt;BR /&gt;&lt;BR /&gt;      exit(0);&lt;BR /&gt;&lt;BR /&gt;    }&lt;BR /&gt;  # ---------------------&lt;BR /&gt;  # parent process, which goes back to accept()&lt;BR /&gt;  # ---------------------&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;close ($Main_TcpSocket);&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Jan 2006 10:08:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700771#M789969</guid>
      <dc:creator>Hofman P A</dc:creator>
      <dc:date>2006-01-02T10:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700772#M789970</link>
      <description>Paul,&lt;BR /&gt; &lt;BR /&gt;I'm not sure whether this will improve things,&lt;BR /&gt;but would you mind trying these wee modifications?&lt;BR /&gt; &lt;BR /&gt;First just to safeguard against the forked child inadvertently tinkering with the listening socket I would suggest that you move the close into the child's block.&lt;BR /&gt; &lt;BR /&gt;e.g.&lt;BR /&gt; &lt;BR /&gt;if ($pid == 0) {&lt;BR /&gt;$Main_TcpSocket-&amp;gt;close;&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;}&lt;BR /&gt;  &lt;BR /&gt;Then I think you could give it a try with a slightly improved sighandler.&lt;BR /&gt; &lt;BR /&gt;1. pull in the WNOHANG into your namespace from the POSIX module.&lt;BR /&gt; &lt;BR /&gt;use POSIX 'WNOHANG';&lt;BR /&gt; &lt;BR /&gt;2. use waitpid() instead of wait() within a loop, as is mentioned in the perlipc POD.&lt;BR /&gt; &lt;BR /&gt;e.g.&lt;BR /&gt; &lt;BR /&gt;$SIG{CHLD} = \&amp;amp;reaper;&lt;BR /&gt;sub reaper {&lt;BR /&gt;while ((my $kid = waitpid(-1, WNOHANG)) &amp;gt; 0 {&lt;BR /&gt;warn "Reaping child PID $pid\n";&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;  &lt;BR /&gt;Hopefully this will end your sporadic parent's exits.&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Jan 2006 07:15:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700772#M789970</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2006-01-03T07:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700773#M789971</link>
      <description>Ralph,&lt;BR /&gt;&lt;BR /&gt;I implement you modifications.&lt;BR /&gt;got a warning now and exit!&lt;BR /&gt;&lt;BR /&gt;TCP socket 5000 on server created . . . . . . . . . .&lt;BR /&gt;Connection established from (rhost=xx.xxx.xxx.xx,rport=62932)&lt;BR /&gt;Wait for new client . . . . .&lt;BR /&gt;- child pid='7571' created -&lt;BR /&gt;- child pid='7571' attemp to closed child -&lt;BR /&gt;warning:Reaping child PID 7571&lt;BR /&gt;&lt;BR /&gt;hpxxxxx:/pathname/phofman -&amp;gt;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Paul&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Jan 2006 03:06:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700773#M789971</guid>
      <dc:creator>Hofman P A</dc:creator>
      <dc:date>2006-01-04T03:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700774#M789972</link>
      <description>Hi Paul,&lt;BR /&gt;  &lt;BR /&gt;I'm not sure if it makes a great deal of a difference, but could apply this slight modification to your accept() loop?&lt;BR /&gt; &lt;BR /&gt;  &lt;BR /&gt;while (1) {&lt;BR /&gt;next unless $new_sock = $Main_TcpSocket-&amp;gt;accept();&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;}&lt;BR /&gt;   &lt;BR /&gt; &lt;BR /&gt;Of course, it would be better to place a loop control variable rather than the unconditional true in the while condition,&lt;BR /&gt;that maybe could be altered by trapping another signal (e.g. SIGINT)&lt;BR /&gt; &lt;BR /&gt;e.g. &lt;BR /&gt; &lt;BR /&gt;$SIG{INT} = sub { $quit++ };&lt;BR /&gt; &lt;BR /&gt;while (!$quit) {&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;}&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Jan 2006 04:34:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700774#M789972</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2006-01-06T04:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: perl fork() problem: child exit() kills parent</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700775#M789973</link>
      <description>Hi Ralph,&lt;BR /&gt;&lt;BR /&gt;It WORKS !!!!!!!!!!!!!!!!!&lt;BR /&gt;&lt;BR /&gt;next unless did the trick .....&lt;BR /&gt;&lt;BR /&gt;Implement both eg. next unless and SIGINT.&lt;BR /&gt;&lt;BR /&gt;I also tried to replace :&lt;BR /&gt;&lt;BR /&gt;#$SIG{CHLD} = \&amp;amp;reaper;&lt;BR /&gt;#sub reaper { while ((my $kid = waitpid(-1, WNOHANG)) &amp;gt; 0) { warn "warning:Reaping child PID $pid\n"; } }&lt;BR /&gt;&lt;BR /&gt;with&lt;BR /&gt;&lt;BR /&gt;$SIG{CHLD} = sub {wait () };&lt;BR /&gt;&lt;BR /&gt;It's still working !!!&lt;BR /&gt;&lt;BR /&gt;===================================&lt;BR /&gt;&lt;BR /&gt;Thanks again for your help and your time !!!&lt;BR /&gt;&lt;BR /&gt;Regards.&lt;BR /&gt;Paul&lt;BR /&gt;&lt;BR /&gt;PS&lt;BR /&gt;points assigned !!&lt;BR /&gt;------&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Jan 2006 03:45:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-fork-problem-child-exit-kills-parent/m-p/3700775#M789973</guid>
      <dc:creator>Hofman P A</dc:creator>
      <dc:date>2006-01-09T03:45:17Z</dc:date>
    </item>
  </channel>
</rss>

