Operating System - HP-UX
1833589 Members
3759 Online
110061 Solutions
New Discussion

Locking a file by same process

 
Tharangini Karthikeyan
Occasional Contributor

Locking a file by same process

Hi
My requirement is , when I give two subsequent open statements opening the same file I want my second open statement to fail saying that the file is already opened.ie. I don't want sharing facility.In AIX we have a flag O_NSHARE in open statement which solves my problem ,In HP 11 this provision is not there.
So if anyone knew please do give me the solution as early as possible.

Regards
Tharangini
3 REPLIES 3
Wodisch
Honored Contributor

Re: Locking a file by same process

Hi,

under whihch UID do you run your program? Usually "root" does not care about file and record locks...

Just an idea,
Wodisch
A. Clay Stephenson
Acclaimed Contributor

Re: Locking a file by same process

HP-UX is not AIX and in fact you are using a non-standard UNIX feature. File locking has always been the responsibility of the programmer. You can change your code to use lockf() to test for locks.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Locking a file by same process

Plan B.

If this is the same process, why not simply use a variable to indicate that you already have the file open.
If it ain't broke, I can fix that.