Re: How to capture pid
From: John McKown (joarmc_at_swbell.net)
Date: 03/03/04
- Next message: John W. Krahn: "Re: Inserting strings into a file"
- Previous message: Andrew Gaffney: "interacting with table layouts using DBI"
- In reply to: Harry Putnam: "How to capture pid"
- Next in thread: John W. Krahn: "Re: How to capture pid"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 2 Mar 2004 17:59:12 -0600 (CST) To: Perl Beginners Mailing List <beginners@perl.org>
On Tue, 2 Mar 2004, Harry Putnam wrote:
>
> What is the handy way to record the pid of $some_process in this
> fake code?
>
> $some_process = 'tcpdump -v -ieth0 >file')
> system("$some_process") or die "Can't start $some_process: $!";
>
> print "Pid is $pid\n";
>
> The process is started by a more elaborate perl script at bootup.
> and restarted every four hours from syslog. Code above is way simplified.
>
>
I don't think you can get the PID when using the system() function. Also,
I am fairly sure that system() does not return control to your Perl script
until the function it invokes finishes. Would something like:
use Errno qw(EAGIN);
...
$someprocess=...
FORK: {
if ($pid=fork) {
print "PID is $pid\n";
}
elsif (defined $pid) {
exec $someprocess;
}
elsif ($!=EAGIN) {
sleep 5; #wait five seconds
redo FORK; #then try again
}
else {
die "Cannot fork to run $someprocess $!";
}
}
-- Maranatha! John McKown
- Next message: John W. Krahn: "Re: Inserting strings into a file"
- Previous message: Andrew Gaffney: "interacting with table layouts using DBI"
- In reply to: Harry Putnam: "How to capture pid"
- Next in thread: John W. Krahn: "Re: How to capture pid"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|