Path: utzoo!utgpu!cunews!bnrgate!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request From: david@bdt.com (David Beckemeyer) Newsgroups: comp.sys.sun Subject: Sun NFS file locking Keywords: No Digest Subjects during Flush Message-ID: <4113@brchh104.bnr.ca> Date: 27 Jun 91 20:22:00 GMT Sender: news@brchh104.bnr.ca Organization: Sunspots, Flush Mode Lines: 32 Approved: sun-spots@rice.edu X-Original-Date: Tue, 18 Jun 1991 23:12:50 GMT I have a network application which must be able to obtain exclusive access to a file. Following the Sun manuals, I'm using hte fcntl() system call, as follows: /* Use fcntl to lock the master control file */ sprintf(tmpnam, "%s/LOCKCTL", dir); lckfd = open(tmpnam, 2); if (lckfd < 0) return(seterror("mklock: cannot open LOCKCTL")); /* lock the whole file for exclusive use */ lck.l_type = F_WRLCK; lck.l_whence = 0; lck.l_start = 0; lck.l_len = 0; if (fcntl(lckfd, F_SETLK, &lck)) { close(lckfd); return(seterror("mklock: F_SETLK failed")); } The problems are that sometimes a process will hang in the fcntl() call; ps reports that the process is in the D state and the WCHAN is "socket". What is going on? It seems like the rcp.lockd process gets confused under certain circumstances. What makes this happen and how does one avoid it? Is there a reliable way to lock files over the network with SunOS? -- David Beckemeyer (david@bdt.COM) | "Lester Moore - Four slugs from a .44 Beckemeyer Development Tools | no Les, no more." P.O. Box 21575, Oakland, CA 94620 | - Headstone at Boot Hill UUCP: {uunet,ucbvax}!unisoft!bdt!david | Tombstone, AZ