in reply to Background process

At its simplest all you need is:

my $pid = system 1, q[java \path\to\yourapp.jar]; ... ## Kill it if it is still running kill 3, $pid if kill 0, $pid;

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.

Replies are listed 'Best First'.
Re^2: Background process
by Your Mother (Archbishop) on Jan 11, 2011 at 18:46 UTC

    Wowzers. I hadn't seen that before and finding the documentation for it took Google's help: perlport.

    As an optimization, may not call the command shell specified in $ENV{PERL5SHELL}. system(1, @args) spawns an external process and immediately returns its process designator, without waiting for it to terminate. Return value may be used subsequently in wait or waitpid. Failure to spawn() a subprocess is indicated by setting $? to "255 << 8". $? is set in a way compatible with Unix (i.e. the exitstatus of the subprocess is obtained by "$?>> 8", as described in the documentation). (Win32)

      Yes. It is very useful. I'm surprised that no one has thought to back port this to *nix.

      The only fly in the ointment is that it truncates the potentially 32-bit return value from the executable to 8-bits.


      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.
        Silly example, but might help.
        #! perl -slw use POSIX qw(:errno_h :sys_wait_h); use constant { RET_SUCCESS => 1, RET_FAILURE => 0, }; sub check_process_signal { my $sig = shift; if ( WIFEXITED($sig) ) { print q{process normal exit}; return RET_SUCCESS; } elsif ( WIFSIGNALED($sig) ) { print q{process terminated because of signal}; return RET_FAILURE; } elsif ( WIFSTOPPED($sig) ) { print q{process is stopped}; return RET_FAILURE; } return RET_SUCCESS; } my $pid = #run your command however.... waitpid( $pid, 0 ); if ( check_process_signal( $? ) ) { ## success... } else { ## failure ... }

        Coded on the fly sorry if there are any errors.

        --Poet