H
hendedav
Gang,
I have looked all over google groups on how to find the pid of
the exec command when using the fork/exec. I will admit that I am not
overly familiar with the workings (I understand the idea though) of
these two commands. Here is what I am working with. I have a perl
script (see below) that calls a shell script that simply counts to
thirty while pausing for one second (basically is a script that does
nothing for 30 seconds so I can see if the PID is correct). What I am
trying to accomplish is trying to find the pid of the binary/script
that is executed from the exec command. If I run the script below,
this would be a sample of what I get:
debian:/tmp# ./test.pl
pid is 6330, parent pid is 6329
debian:/tmp# ps a
PID TTY STAT TIME COMMAND
2545 tty1 Ss+ 0:00 /sbin/getty 38400 tty1
2546 tty2 Ss+ 0:00 /sbin/getty 38400 tty2
2547 tty3 Ss+ 0:00 /sbin/getty 38400 tty3
2548 tty4 Ss+ 0:00 /sbin/getty 38400 tty4
2551 tty5 Ss+ 0:00 /sbin/getty 38400 tty5
2552 tty6 Ss+ 0:00 /sbin/getty 38400 tty6
2569 pts/1 Ss 0:00 -bash
2578 pts/1 S 0:00 bash
3104 pts/0 Ss+ 0:00 -bash
6331 pts/1 S 0:00 /bin/sh ./test.sh
6346 pts/1 S 0:00 sleep 1
6347 pts/1 R+ 0:00 ps a
As you can see neither of the pids is the one from the exec command.
I also tried using the open command (which returns the pid correctly),
but I can not background the process (using an & at the end of the
command). I need to find the pid of the exec command within the
parent perl script so that I can track it. Any help would greatly be
appreciated.
Thanks,
Dave
#!/usr/bin/perl
if (defined (my $pid = fork)) {
if ($pid) { # this test runs if the fork was successful
# eliminates the zombies
local $SIG{CHLD} = "IGNORE";
print "pid is $pid\n, parent pid is $$\n";
} else { # the following line runs in the child
exec("./test.sh &");
print "child pid is: $$\n";
exit();
}
} else {
print "there was a problem executing the script\n";
}
I have looked all over google groups on how to find the pid of
the exec command when using the fork/exec. I will admit that I am not
overly familiar with the workings (I understand the idea though) of
these two commands. Here is what I am working with. I have a perl
script (see below) that calls a shell script that simply counts to
thirty while pausing for one second (basically is a script that does
nothing for 30 seconds so I can see if the PID is correct). What I am
trying to accomplish is trying to find the pid of the binary/script
that is executed from the exec command. If I run the script below,
this would be a sample of what I get:
debian:/tmp# ./test.pl
pid is 6330, parent pid is 6329
debian:/tmp# ps a
PID TTY STAT TIME COMMAND
2545 tty1 Ss+ 0:00 /sbin/getty 38400 tty1
2546 tty2 Ss+ 0:00 /sbin/getty 38400 tty2
2547 tty3 Ss+ 0:00 /sbin/getty 38400 tty3
2548 tty4 Ss+ 0:00 /sbin/getty 38400 tty4
2551 tty5 Ss+ 0:00 /sbin/getty 38400 tty5
2552 tty6 Ss+ 0:00 /sbin/getty 38400 tty6
2569 pts/1 Ss 0:00 -bash
2578 pts/1 S 0:00 bash
3104 pts/0 Ss+ 0:00 -bash
6331 pts/1 S 0:00 /bin/sh ./test.sh
6346 pts/1 S 0:00 sleep 1
6347 pts/1 R+ 0:00 ps a
As you can see neither of the pids is the one from the exec command.
I also tried using the open command (which returns the pid correctly),
but I can not background the process (using an & at the end of the
command). I need to find the pid of the exec command within the
parent perl script so that I can track it. Any help would greatly be
appreciated.
Thanks,
Dave
#!/usr/bin/perl
if (defined (my $pid = fork)) {
if ($pid) { # this test runs if the fork was successful
# eliminates the zombies
local $SIG{CHLD} = "IGNORE";
print "pid is $pid\n, parent pid is $$\n";
} else { # the following line runs in the child
exec("./test.sh &");
print "child pid is: $$\n";
exit();
}
} else {
print "there was a problem executing the script\n";
}