1) I execute the first program with the following statements:
$READLOCK = 1;
$EXCLUSIVE = 2;
$UNLOCK = 8;
unless (open(INFILE, "test.tmp"))
&message("Unable to open in file");
flock (INFILE, $READLOCK);
flock (INFILE, $UNLOCK);
3) I execute a second pgm immediately after the first. The second pgm tries to read the same file(i.e. INFILE):
The second file successfully reads the INFILE before the first program completes; in other words, the $READLOCK in the first pgm is not locking file INFILE. By the way, the $EXCLUSIVE works correctly!!
Platform: UNIX - Solaris
object: $READLOCK must prevent any other file(i.e. read lock) from reading it. One solution is to execute chmod in the first pgm and set INFILE to 333. After it is complete, change it back to 644. However, I do not like this hack!!