in reply to Re: how to kill background process when script exit?
in thread how to kill background process when script exit?
REALLY kludgy, but it works :-)...
#!/usr/bin/perl my($JAVA_CLASSPATH) = @ARGV; $java_command = "java -classpath $JAVA_CLASSPATH TextEntry"; system("$java_command 2> /dev/null &"); $kid = `ps aux | grep "$java_command" | grep -v 'grep'`; $kid =~ s@^.*?\s+([0-9]+).*@$1@s; END { if ($kid) { kill 9 => $kid; # bang }; }; print "pid is: $pid\n\npress return to exit..."; <STDIN>
I would really like to find a more elegant way however.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to kill background process when script exit?
by eyepopslikeamosquito (Archbishop) on Feb 20, 2011 at 00:23 UTC | |
by Allasso (Monk) on Feb 20, 2011 at 01:01 UTC | |
by Allasso (Monk) on Feb 21, 2011 at 14:04 UTC | |
by Anonymous Monk on Feb 21, 2011 at 14:15 UTC | |
by Allasso (Monk) on Feb 21, 2011 at 17:49 UTC | |
|
Re^3: how to kill background process when script exit?
by Allasso (Monk) on Feb 20, 2011 at 00:23 UTC |