in reply to system function is returning status -1 when running a unix command

Sounds like your DB stuff is messing with SIGCHLD.
$ perl -wle'$SIG{CHLD}="IGNORE"; print system("ls -d ."); print $!' . -1 No child processes

system is basically fork + exec (in the child) + waitpid (in the parent). In the above example, children are auto-reaped, so system has no child to wait for, so it returns an error.

strace (or truss or whatever it's called on Solaris) would confirm this diagnosis.

Update: Added last line.

Replies are listed 'Best First'.
Re^2: system function is returning status -1 when running a unix command
by repellent (Priest) on Apr 08, 2009 at 18:16 UTC
    ikegami, could you please explain what is going on here:
    > perl -wle ' $SIG{CHLD}="IGNORE"; $! = 33; print system("ls -d ."); print -+-$!; print $!; print -+-$!' . -1 33 No child processes 10

    It seems that string-ifying "$!" changes its value.

      print can result in system calls. $! is meaningless after the first print.

      $ perl -wle' $SIG{CHLD}="IGNORE"; $! = 0; my $rv = system("ls -d ."); my $errno = $!; print $rv; print 0+$errno; print $errno; print 0+$errno; ' . -1 10 No child processes 10

      Note that 0+ is much easier to understand than -+-, and it conveys the intent much better.