[KLUG Programming] perl fork question
Adam Williams
programming@kalamazoolinux.org
Fri, 19 Sep 2003 16:11:59 -0400
> > > 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.
> How much data are you trying to pass? If you're doing something
> important and long-lived, with small data, you could create a Unix
> domain socket and pass UDP messages over it.
> If your needs are rather lightweight, it is also possible to fork off a
> program and then tie arbitrary filehandles to each other in C, and I
> imagine Perl is much the same:
> http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch16_11.htm
> Or use SysV IPC, using IPC::Msg:
> http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch16_13.htm
I have a really good book on System V IPC you can borrow. Sys V IPC has
the advantage of being -really-really-bloody-fast-. The book covers C,
but I'd image there are perl equivalents for everything.
Doesn't perl support threading? You still need IPC, but IMHO, threading
is easier than forking since you don't have cross-process issues
(security, name of message queue propogation, etc...)