in reply to Re^2: how to kill background process when script exit?
in thread how to kill background process when script exit?
The problem is that $kid is the pid of the shell you launched (since you provided a shell command), and it exits as soon as it launches java. You could avoid the shell.
use IPC::Open3 qw( open3 ); { open(local *CHILD_STDIN, '<', '/dev/null') or die; open(local *CHILD_STDERR, '>', '/dev/null') or die; local *FROM_CHILD; my $kid = open3('<CHILD_STDIN', \*FROM_CHILD, '>CHILD_STDERR', 'java', 'JavaApp' ); ... }
Higher-level solutions possible using IPC::Run3 and IPC::Run.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: how to kill background process when script exit?
by Allasso (Monk) on Feb 20, 2011 at 21:07 UTC |