in reply to Re: system() call failure
in thread system() call failure

My bad, the above was completely inacurate. I started doing some searching around to the cause of the annoying error, and I reduced it down to this:

#!/usr/local/bin/perl $SIG{ 'CHLD' } = sub { my $pid = wait(); print "Got $pid\n"; }; system("/bin/ls > /dev/null") == 0 || print "system exited with $?, error is \"$!\"\n";

If you take out the signal handler, it works. Now I'm completely lost...

By the way, this is the uname -a output:

SunOS xxxxxx 5.7 Generic sun4u sparc SUNW,Ultra-5_10

ANY ideas??

Replies are listed 'Best First'.
Re: Re: Re: system() call failure
by no_slogan (Deacon) on May 15, 2001 at 04:09 UTC
    system() does a wait() for the /bin/ls process to complete. When the process ends, your handler jumps in and grabs it, and system() gets nothing, which isn't what it wanted. If you run a command that has a side effect, you should see that it actually does get executed.

    It's interesting that it worked on Linux but not Solaris. Must be some difference in the way they deliver signals.

    Best solution is probably not to mix $SIG{CHLD} with system(). There are a couple of threads around here that might be useful... try a search or two.

      I ended up overloading the system() function call with my version of it. The truth is *I* don't need system(), but other people using my framework do. So I need account for this

      anyway, all I did was to make sure that the $SIG{'CHLD'} gets masked by local $SIG{'CHLD'} = <em>blah</em>, and the rest is just your typical fork()/exec()

      Boy, that was annoying! Thanks to both clintp and no_slogan for your help :-)

      just letting you guys know what happened... So it turns out yes, you must be correct: when system() forks, for some reason the $SIG{ 'CHLD' } that I defined gets called.

      I don't really need to call system(), but others who use my code do, so I decided on just overloading the system() function call with a version that uses a local $SIG{ 'CHLD' }

      It works now :-)

      Thanks for your help..