Re: How to capture pid

From: Harry Putnam (reader_at_newsguy.com)
Date: 03/03/04


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? 


Relevant Pages

  • Re: LTT user input
    ... and to that end have taken the existing trace infrastructure ... script for that event (if there's a handler defined for the event ... This gives the script a chance to do whatever Perlish thing it ... syscall totals to individual syscall totals for each pid. ...
    (Linux-Kernel)
  • Re: Fwd: Any way to find the network usage by a process?
    ... Here's a variation of Jose's script that uses the networking tapset and prints top-like output for transmits and receives. ... Much of the activity shows up under pid 0, ... Can anyone suggest better probe points to get transmits and receives by pid? ... execname[pid()] = execname ...
    (Linux-Kernel)
  • Re: Two processes with PID == 0
    ... In my case, the process (script ... see that your second process with pid 0 is ... Protect your identity with Yahoo! ... To unsubscribe, ...
    (freebsd-current)
  • DESTROY executed twice
    ... I wrote a script that forks several child ... In MyModules/MyClass.pm there is a DESTROY method for taking some ... houskeeping actions (closing database handle and deleting PID file): ... When running the script, everything works fine except for each ...
    (perl.beginners)
  • Re: pulling my hair: doodle 0.6.5-3 update / doodled unstoppable
    ... which I fail to understand; there is no PID ... try to castrate the pre-removal script and force the upgrade. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)