Re: How to capture pid
From: Harry Putnam (reader_at_newsguy.com)
Date: 03/03/04
- Next message: John W. Krahn: "Re: How to capture pid"
- Previous message: John W. Krahn: "Re: Reading File & grep according item 5 and sorting"
- In reply to: Rob Hanson: "RE: How to capture pid"
- Next in thread: Zentara: "Re: How to capture pid"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Tue, 02 Mar 2004 18:07:58 -0600
"Hanson, Rob" <rhanson@aptegrity.com> writes:
> I'm not sure, probably by forking and execing. It won't return the result
> code from the other program though.
>
>
> $some_process = 'tcpdump -v -ieth0 >file';
>
> my $pid = fork();
> unless ($pid) {
> exec($some_process);
> die "Can't start $some_process: $!";
> }
>
> print "Pid is $pid\n";
>
For some reason the pid printed does not match the output of ps:
actual sample script"
---
#!/usr/local/bin/perl -w
my $cmd = 'tcpdump -v -ttt -i rl0 -w ';
my $fpath = "/var/log/dump";
my $base_fname = "dump_all";
my ($afname);
$afname = "$fpath" . "/" . "$base_fname";
my $pid = fork();
unless ($pid) {
exec("$cmd $afname &");
die "Can't start $cmd: $!";
}
print "Pid is $pid\n";
---
Script output:
# dump_all.pl
Pid is 15173
[fwobsd:root] /root
# tcpdump: listening on rl0
ps wwaux|grep tcpdump
root 30335 0.0 1.6 1116 1048 p0 S 6:03PM 0:00.02
tcpdump -v -ttt -i rl0 -w /var/log/dump/dump_all (tcpdump-3.4.0-or)
Note the script outputs 15173 and ps shows 30335
Do you have an idea what is happening here?
- Next message: John W. Krahn: "Re: How to capture pid"
- Previous message: John W. Krahn: "Re: Reading File & grep according item 5 and sorting"
- In reply to: Rob Hanson: "RE: How to capture pid"
- Next in thread: Zentara: "Re: How to capture pid"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|