lockfile/unix/c

K.LAUX rkl1 at hound.UUCP
Fri Apr 14 01:59:30 AEST 1989


In article <6307 at homxc.ATT.COM>, iluvu at 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



More information about the Comp.unix.questions mailing list