Hello, perlmonks,

I am seeking advice on diagnosing a problem related to a Perl program (which I inherited) that makes use of fork(). The basic problem seems to be that some of the forked sub-processes immediately exit without doing any work. When those processes are reaped (with wait()), $? is set to 11, which I believe is the error code for "resource temporarily unavailable, try again". I am trying to determine which resource is unavailable. The environment is Linux/Centos 7

The basic structure of this program is as follows:

Here's a pseudo code outline (note: this won't actually re-create my problem, of course):

# Initialization # Read input file, calls to system('bowtie2', ...) and system('samtool +s', ...) use strict; use warnings; use Carp qw(confess); use Sys::Info::Device::CPU; use Sys::Info::Constants qw( :device_cpu ); my $info = Sys::Info->new; my $cpu = $info->device( CPU => {} ); my $nthreads = $cpu->count; print "$nthreads threads\n"; while ($nthreads--) { my $pid = fork; confess ("Can't fork: $!") unless defined $pid; if (! $pid) { print "child process: $$\n"; # this line never gets executed +by some of the children # Do a bunch of processing using intermediate files as input, usin +g Bio::DB::Sam->get_features_by_location() to access intermediate fil +es exit 0; } } # parent continues here: my $pid = 0; my $ok = 1; while ($pid != -1) { $pid = wait; last if $pid == -1; my $err=$?; if ($err) { print("one of the children died: pid=$pid, err=$err\n"); $ok = 0; } } if (! $ok) { confess "some child processes died."; } print "all done, yay\n";

In all of the processes, the line directly after the fork confess("Can't fork: $!") unless defined $fork; never gets executed. I infer that the fork itself did happen.

But some of the processes, depending on the input file, are reaped immediately, with $err=11 (EAGAIN). I surmise I am running short of some resource, but which one? I have increased the limits for the following resources to values (by editing /etc/security/limits.conf, and then rebooting) that I believe should be more than sufficient, to no avail:

I've also increased swap space via swap files.

Short or restructuring the code to use exec(), which I've considered, do any wise monks have suggestions as to:

My thanks for all answers, insights, and useful comments


In reply to Trouble with fork() by phonybone_monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.