Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

folks I am working in a project called process scheduler and the intention is to run processes parallely.We are using using a pre-forked server model to do this.We use the DB_file(with DB_filelock) to a file and the forked children will read the values from the file to run the job.(The forked process will run the job and write the status of the job into one more file).The process works fine except I get an error "cant call seq on an undefined variable",when I read the status file.I also tested the program to check and make sure that locking is not a problem.This I did it by running the same program (that the program which access the same file in a loop) and I could see the program to finish with no issue.If you have come across this problem,please let me know. Thanks Kris

Replies are listed 'Best First'.
Re: DB_Filelock issues
by chromatic (Archbishop) on Jun 07, 2002 at 04:17 UTC
    File locking across fork() calls depends greatly upon your operating system's support of flock() (and, I suppose, fork()). You'll probably need to follow up with a bit more information about your environment and some code. (The alternative is that someone will make a wild guess that turns out to be right. If it were up to me, I'd say "don't flock before you fork".)
      Stevens explicitely states that file locks by the parent are not inherited by the child, without stating any differences between BSD and SysV.

      You said, "don't flock() before you fork", but there's a (neat?) hack involving flocking before a fork to make sure a parent does something before a child can:

      1. flock a file exclusively.
      2. fork.
      3. let the child flock the file.
      4. now the parent can do her stuff.
      5. parent releases the flock.
      6. child releases the flock.
      7. both child and parent go their merry ways.
      I was *this* close to actually use that trick (in a C program) earlier this week.

      Abigail