perl, forking and broken file handles
Taavi Burns
jaaaarel-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Wed May 4 18:29:22 UTC 2005
On 5/4/05, billt-lxSQFCZeNF4 at public.gmane.org <billt-lxSQFCZeNF4 at public.gmane.org> wrote:
> What you want to do is pass as parameters (global variables) the names of the files you want to open to the child process and open up the DB and files after the fork.
Why on earth would you want to do that? Just have the filename set in
a variable in the program, and delay opening it until the child is
forked. The child will have exactly the same variable definitions:
for (items)
{
set current_item;
pid = fork();
if (pid == 0)
{
fh = open(current_item);
do stuff;
exit;
}
fh = open(current_item);
Do that other stuff (be sure not to walk on the child);
}
About the only time you'd want to keep filehandles open between parent
and child is, afaik, if you're using pipes for IPC; in that case the
parent would open two pipes, and write to pipe 1 and read from pipe 2
while the child reads from pipe 1 and writes to pipe 2. (or just use
one pipe if you only need one-way communication)
--
taa
/*eof*/
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list