in reply to SIG{ALRM} to help kill external program

The behaviors of backticks are described in `STRING` in perlop. Backticks only return once the external program has finished execution - otherwise, how would perl know it had returned to you the entire output? Therefore, you can't use a $SIG{ALRM} to control it - the child process has control of the thread.

For the simple case, you can follow roboticus's suggestion to use fork.(Update: See cdarke's comment below) You might also consider threads (core) or POE for more complicated queuing behaviors. If you are feeling adventurous, you can combine a piped open with select or $SIG{ALRM} - see Using open() for IPC some some basics.

  • Comment on Re: SIG{ALRM} to help kill external program

Replies are listed 'Best First'.
Re^2: SIG{ALRM} to help kill external program
by locked0wn (Acolyte) on Oct 19, 2010 at 18:00 UTC
    kennethk,
    I want to thank you for your suggestion of using threads. I have implemented a dual thread setup that uses a shared variable for tracking completion of thread 1, which launches the external application. Thread 2 monitors the value of the shared variable, and after several loops of checking state on the variable, it either ends the thread (which means that thread 1 completes), or it kills all threads, because thread 1 has been hung up (which means the external app did not complete. It works very well, and I intend to post after I clean up the code for final. Thank you very much for everyones' input.