Mailing List Archive

Bad file number under Linux
We've come across a very strange problem, and we're not sure of the
cause (whether perl, linux, or our program). Here's the scenario: We
have two perl scripts (we'll call them A and B). Script A initially
does a fork to become a daemon (using the sample from the Perl
programming book and $SIG{'CHLD'} = sub { wait }; to prevent zombies).
Script A is meant to run forever and periodically do a fork; in the
child part of the fork it does an exec(script B). Script B then runs,
exits, and Script A harvests the PID.

Our system setup is as follows: Perl 5.001m, Linux v1.2.13, NCSA
httpd 1.4.2 and apache httpd 0.6.5. When script A is run from the BASH
shell, everything works fine. When it is started via CGI (another
script---Script C does a system(Script A) to start script A), script A
runs fine, but when it tries to start script B, it dies right away with
a return status of 9 (bad file number). Script B doesn't even START to
run (we have logging setup to log the start of the script---it doesn't
execute).

We tried both NCSA and apache HTTPd---same result. We also tried it
on a Sun Sparc 5---same result. So it doesn't seem like a linux
problem. But who knows....

Any help on this problem would be appreciated. Our current
workaround is to start Script A from the shell, but we want to do it via
WWW. The full source code of our scripts is available if anyone is
interested.

Thanks in advance,

Larry