Operating System - Linux
1831043 Members
2416 Online
110019 Solutions
New Discussion

exclusive access on files

 
Marco Salvi
Advisor

exclusive access on files

Is there any way in C to open a file (on HP-UX) having an exclusive access for writing?
I mean I have just one process that have to write in this file while other programs can only read. Is it possible?
On other Unix flavour there is the flag “O_RSHARE” for the “open” api. On HP?

Thanks.
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor

Re: exclusive access on files

There is no direct equivalent but you can use
lockf() or fcntl() to do this. If you set the setgid bit on the data file then the locks become mandatory rather than advisory.
A far simpler solution and one that would be portable across all flavors of UNIX is to set the permissions to 640 or 644 and the "writer" process would have the effective UID of the owner of the file.
If it ain't broke, I can fix that.