in reply to system() returns -1 with $SIG{CHLD}?

Are you forgetting that system returns a combination of the return status code together with the signal number with which the code was run ?

Probably worth investigating $! - as suggested in ...Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason)...

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

Replies are listed 'Best First'.
Re^2: system() returns -1 with $SIG{CHLD}?
by ikegami (Patriarch) on Feb 11, 2009 at 19:48 UTC

    When running the code I get -1 from wait and 0 from system. $! tells me No child processes. That makes sense since both system also does a wait.

    Why are you using $SIG{CHLD} with system? You shouldn't wait for a child launched using system.

      Why are you using $SIG{CHLD} with system? You shouldn't wait for a child launched using system.

      This was just a sample piece of code distilled down from a much larger perl program. In the big program, I'm running commands in the background, that take an arbitrary amount of time to complete. I don't want to be leaving any zombie processes around, so I used wait() with $SIG{CHLD} to mitigate this.

      Should I be doing something differently here, or should I be responsible for managing the handling of $SIG{CHLD} whenever I want to run a system() command?

      update: The zombies are left after forking a background process, not using system. I didn't make that clear

        Should I be doing something differently here

        Yes, you shouldn't wait for a child started with system.

        I don't want to be leaving any zombie processes around

        system doesn't leave zombies cause it waits.