[KLUG Programming] perl fork question

Adam Williams programming@kalamazoolinux.org
Fri, 19 Sep 2003 10:56:59 -0400


> When you fork in perl, my understanding is that the programs variables
> are shared, or more specifically that the child and parent have all of
> the existing variables but each process then has it's own copy of the
> variables in the program with the same initial state. 

This isn't just perl, but the standard way a fork() works.

>  How can I have a
> variable that can be modified in the child and the parent will see it's
> change. 

IPC (Inter-Process Communication).  Can you create a message queue in
perl?  It is pretty easy in C (on UNIX at least).

>  What I am interested in specifically is a filehandle.  I would
> be willing to print a variable to a file in the child and read it in the
> parent but I am not sure how to accomplish this with a scalar
> filehandle.

I don't think you can pass filehandles as values.  The fork'd child does
inherit all the filehandles however.