Xref: utzoo comp.unix.questions:15140 comp.sys.mips:8 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!csd4.milw.wisc.edu!indri!uakari!bin From: bin@primate.wisc.edu (Brain in Neutral) Newsgroups: comp.unix.questions,comp.sys.mips Subject: Should two exclusive flock(2)'s by same process succeed? Message-ID: <136@uakari.primate.wisc.edu> Date: 24 Jul 89 17:03:50 GMT Organization: UW-Madison Primate Center Lines: 70 Should a single process be able to acquire an exclusive lock on a file twice? It would seem to me "no", given the usual meaning of "exclusive". However, differing systems give me differing results for the following program. # include # include main () { extern int errno; int f1, f2; f1 = open ("junk", O_WRONLY|O_CREAT, 0644); if (f1 < 0) { perror ("f1 open"); exit (1); } printf ("f1 opened\n"); if (flock (f1, LOCK_EX|LOCK_NB) < 0) { if (errno == EWOULDBLOCK) { perror ("f1 flock1"); exit (1); } perror ("f1 flock2"); exit(1); } printf ("f1 locked\n"); f2 = open ("junk", O_WRONLY|O_CREAT, 0644); if (f2 < 0) { perror ("f2 open"); exit (1); } printf ("f2 opened\n"); if (flock (f2, LOCK_EX|LOCK_NB) < 0) { if (errno == EWOULDBLOCK) { perror ("f2 flock1"); exit (1); } perror ("f2 flock2"); exit(1); } printf ("f2 locked\n"); } On a VAX (Ultrix 2.2 or 1.2) I get the following output, as expected: f1 opened f1 locked f2 opened f2 flock1: Operation would block On a MIPS M/120 (RISC/os 4.0) I get, unexpectedly: f1 opened f1 locked f2 opened f2 locked In other words, the process acquires two exclusive locks. Am I correct in thinking this is a bug in flock? Paul DuBois dubois@primate.wisc.edu