On Tuesday 24 July 2007 11:21, Gatsby wrote: > The problem is, if I output $$, then it only ever outputs the process ID of > the parent httpd process, not the actual child process itself.
This is a known feature (at least I have already met it). It is caused by apache doing the fork by itself in combination with perl's fork operator. Perl caches the result of the getpid and getppid syscalls. So if a process calls fork at C-level perl thinks its cache is still valid even in the child. You can try this feature also this way: $ perl -Mstrict \ -e 'require "syscall.ph"; syscall &SYS_fork; print "pid=$$ ".syscall(&SYS_getpid). " ppid=".getppid." ".syscall(&SYS_getppid)."\n"' pid=5835 5836 ppid=4260 5835 pid=5835 5835 ppid=4260 4260 So, to solve your problem you can either use the syscall interface or try my Perl::AfterFork or Rafael's Linux::Pid. If you decide to use my module put this line in your ChildInit handler: use Perl::AfterFork; # or require Perl::AfterFork::reinit(); Here the result: $ perl -Mstrict -MPerl::AfterFork \ -e 'require "syscall.ph"; syscall &SYS_fork; Perl::AfterFork::reinit(); print "pid=$$ ".syscall(&SYS_getpid). " ppid=".getppid." ".syscall(&SYS_getppid)."\n"' pid=6192 6192 ppid=6191 6191 pid=6191 6191 ppid=4260 4260 Torsten
pgpfJLGkVatd2.pgp
Description: PGP signature