in reply to Re: Ulimit makes program hang
in thread Ulimit makes program hang

Unfortunatelly sleeping doesn't solve the problem.

I have tested all more throughly and modified program:
#!/usr/bin/perl -w my $x = $ARGV[0] + 1; print STDERR "$x\n"; `./my_program $x`;

Now I ran commands:
(ulimit -u100; ./my_program) (ulimit -u50; ./my_program) (ulimit -u20; ./my_program)

The first one hang on 95-th iteration. The second hang on 45-th iteration. The third one hang on 15-th iteration. So wen you set maximum number or processes to N (ulimit -u<N>), then program hangs on N-5 iteration.
I want that program to fail (return nonzero code) when no processes are available...

Replies are listed 'Best First'.
Re^3: Ulimit makes program hang
by Hue-Bond (Priest) on Aug 13, 2008 at 14:37 UTC

    ulimit sets the maximum number of process that your user can run. Since you are likely to be running some other processes (for instance, your shell), it comes as no surprise that there are fewer "slots" available for other processes.

    --
    David Serrano

      Yes -- you're right. My question is why perl hangs instead of giving up and telling user "unable to fork".
Re^3: Ulimit makes program hang
by Bloodnok (Vicar) on Aug 13, 2008 at 14:42 UTC
    Hi ,

    I strongly suspect that, if you re-insert the sleep before shelling out, your results will be modified since the perl process won't otherwise have enough time to complete the print.

    Have you tried the fork/exec approach ?

    Have you tried an even lower limit and running the program using truss (or is it strace on linux) ?

    As an afterthought, I do wonder if you've uncovered a bug in perl...

    A user level that continues to overstate my experience :-))
      After insterting sleep before shelling out I get exactly same results.

      I'm not a system programmer to analyse strace output...sorry.

      I have tried fork and exec this way:
      #!/usr/bin/perl -w my $x = $ARGV[0] + 1; print STDERR "$x\n"; if (!defined($child_pid = fork())) { die "cannot fork: $!"; } elsif ($child_pid) { waitpid($child_pid, 0); } else { exec "$0 $x"; }
      This program never hangs -- always says cannot fork: Resource temporarily unavailable at ./fork_wait line 7.
      But I must grab output of command so I can't use this solution.
        ...as I suspected, using the evidence of your OP and this posting, I think you've got enough to raise a perl bug against the backtick (``) operator - I think it should die with a similar fatal error.

        Section 16 of the Perl Cookbook should provide you with some background in order to progress further with capturing output from a command ...

        HTH ,

        A user level that continues to overstate my experience :-))