in reply to Re^2: Executing a process in the background AND getting its pid
in thread Executing a process in the background AND getting its pid

Let's say in another words: You have a Perl program, "A", runs with PID 32237. A forks another process, "B", with PID 31238. So, B is the child process of A. B then exec's another program, "C". Now, C is replacing the process B and using B's PID which is 31238. The original parent, which is "A", needs to know the PID of C. That is 31238. Is it correct?

Consider this:

# /tmp/child-child.pl print "I'm exec'd: $$\n";
Then in the main program (/tmp/main.pl):
#!/usr/bin/perl use strict; use warnings; print "I'm parent ($0): $$\n"; my $child = fork; defined $child or die "Can't fork: $!\n"; unless ($child) { print "I'm child ($0): $$\n"; exec $^X, '/tmp/child-child.pl'; }
The output is:
$ perl /tmp/main.pl I'm parent (/tmp/main.pl): 12499 I'm child (/tmp/main.pl): 12500 I'm exec'd (/tmp/child-child.pl): 12500

Update: fixed typo


Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!