Xref: utzoo comp.unix.questions:12846 comp.lang.c:17627 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!ames!pasteur!ucbvax!decwrl!labrea!rutgers!att!homxb!hound!rkl1 From: rkl1@hound.UUCP (K.LAUX) Newsgroups: comp.unix.questions,comp.lang.c Subject: Re: lockfile/unix/c Keywords: c, unix, lockf Message-ID: <3012@hound.UUCP> Date: 13 Apr 89 15:59:30 GMT References: <6307@homxc.ATT.COM> Organization: AT&T Bell Laboratories, Holmdel Lines: 19 In article <6307@homxc.ATT.COM>, iluvu@homxc.ATT.COM (S.RAVIKUMAR) writes: | I tried to restrict access to a shared resource between | processes using the unix system call "lockf". The piece of code | is as follows: | | fd = open(FILENAME, O_CREAT, 0666); | lockf(fd, F_LOCK, (long)0); | | "lockf" always returns with an error and errno is set to "Bad | file descriptor". Any help or suggestions are welcome. Sounds like the open call is returning an error. You should check for this before issuing the lockf call. Also, after opening a file with O_CREAT, I close the file, then reopen it with another open call, because O_CREAT will only let you write to the file, and I usually need read/write permission. --rkl