T
Ting Wang
Is there a way to get the process ID, which is started with system()?
e.g
#! /usr/bin/perl
#test.pl
#platform: linux
system(app);
system(app);
and i want to kill the first "app". With
sub kill_app{
my $app = "\"".$_[0]."\"";
if ($_[1]) {
my $pid = $_[1];
$line = `ps -ef |grep $app|grep $pid|grep -v grep`;
}else
{
$line = `ps -ef |grep $app|grep -v grep`;
}
@ps_info = split (/\s+/, $line);
$pid = $ps_info[1];
if ($pid =~ /[1-9][0-9]+/) {
kill 9, $pid;
}
}
will both app be killed. and "kill_app" has problem when the application
is "grep".
in shell script i can use $! get the pid.
How can i do it with perl?
I really do not want to add a small shell script in perl.
Thanks
e.g
#! /usr/bin/perl
#test.pl
#platform: linux
system(app);
system(app);
and i want to kill the first "app". With
sub kill_app{
my $app = "\"".$_[0]."\"";
if ($_[1]) {
my $pid = $_[1];
$line = `ps -ef |grep $app|grep $pid|grep -v grep`;
}else
{
$line = `ps -ef |grep $app|grep -v grep`;
}
@ps_info = split (/\s+/, $line);
$pid = $ps_info[1];
if ($pid =~ /[1-9][0-9]+/) {
kill 9, $pid;
}
}
will both app be killed. and "kill_app" has problem when the application
is "grep".
in shell script i can use $! get the pid.
How can i do it with perl?
I really do not want to add a small shell script in perl.
Thanks