in reply to Re: Run and Stop another program in perl
in thread Run and Stop another program in perl

Funny that both you and BrowserUK decide to kill using SIGKILL. That's not very friendly, and not "the appropriate way" - it doesn't give the program a chance to shutdown gracefully (for instance, if the killed process would be a Perl program, sending it SIGKILL robs the program of its opportunity to run END blocks. Or to call DESTROY. Or to cleanly shut down database connections.). Send it a SIGTERM (often 15, but technically, it's architecture dependent - check $Config::Config{sig_name} if you want to cover portability issues).

Replies are listed 'Best First'.
Re^3: Run and Stop another program in perl
by BrowserUk (Patriarch) on Aug 21, 2010 at 09:03 UTC

    In my case, there is good reason for that. Did you notice the OPs program name: program.exe?

    On win32, it makes no difference. The following code does kill 15, but notice that it is reported by the terminatng process as sigbreak:

    Perl> $pid = open CMD, '-|', q[perl.exe -le"$SIG{TERM}=sub{print 'here +' }; $|++; print ++$i while sleep 1"] or die $!;; Perl> print scalar <CMD> for 1 .. 10;; 1 2 3 4 5 6 7 8 9 10 Perl> kill 15, $pid;; Terminating on signal SIGBREAK(21)

    The pseudo signals perl provides on win32 are useful, but limited. And bear very little resemblance to POSIX signal handling.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.