|There's more than one way to do things|
Writing to one file from multiple processesby KianTern (Acolyte)
|on Mar 06, 2008 at 09:02 UTC||Need Help??|
KianTern has asked for the
wisdom of the Perl Monks concerning the following question:
I'm wiring a multipart (4-5 forked processes) Linux daemon which off course needs logging.
I've created a simple class which I use in each daemon part.
This is not very convenient to use 4-5 log files for one daemon.
I want to use only one file to write all the logging info, but I'm afraid of a situation where 2 parts will try write simultaneously to the same file.
I've read that this can be avoided by flock() but it also says that flock() works on file handles, which in my case are unique in each process(class instance).
Can you please help me to find a convenient way to lock the file before writing so it wouldn't be possible to access from another process.
PS. I want to avoid creating a lock file if possible.