I am unable to duplicate what you describe. I modified your code to see if the pid file contains a pid after returning from the wait() call, and it does:
#!/usr/bin/perl use strict; use warnings; my $fork_pid = fork(); if ($fork_pid == 0) { write_pid(); exit 0; } elsif ($fork_pid) { wait; open my $FILEH, '<', 'mypid.txt'; my $line = <$FILEH>; close $FILEH; print "I am $$. Saw child pid $line"; } else { die "Couldn't fork"; } sub write_pid { open my $FILEH, '>', 'mypid.txt'; print $FILEH $$ . "\n"; close $FILEH; }
When I run it, I get this:
$ ./blah.pl I am 7202. Saw child pid 7203
Indicating that the pid file is being written properly with the child's pid.
In reply to Re: Fork child process always finishes with parent
by markkawika
in thread Fork child process always finishes with parent
by Rogue
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |