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

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.

Replies are listed 'Best First'.
Re^3: system() returns -1 with $SIG{CHLD}?
by cmv (Chaplain) on Feb 11, 2009 at 21:48 UTC
    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.