Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'd like to flock() a socket passed to a child process
via a filehandle (STDOUT).
I've tried doing this in the child:
flock(STDOUT, 2); # LOCK_EX = 2 - grab lock
syswrite(STDOUT, "$message");
flock(STDOUT, 8); # LOCK_UN = 8 - free lock
But flock() doesn't work, I think because all children
share the same sockethandle - flock() is always
successful in gaining a lock - it seems flock() does
not work across child processes.
One solution I've heard of is to open a new filehandle in
each child - and flock on this per-child filehandle.
Does anyone know how to do that to a socket?
Is something like this feasible?
open(CHILDHANDLE); # not sure how to do this?
*CHILDHANDLE = *STDOUT; # unique handle on parent socket
flock(CHILDHANDLE, 2); # LOCK_EX = 2 - grab lock
syswrite(CHILDHANDLE, "$message");
flock(CHILDHANDLE, 8); # LOCK_UN = 8 - free lock
Any perls of wisdom would be much appreciated...
Nige
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: flocking a socket
by kschwab (Vicar) on Jan 25, 2002 at 19:54 UTC | |
|
Re: flocking a socket
by clintp (Curate) on Jan 25, 2002 at 19:45 UTC |