how can u lock files in c
question on files
Collapse
X
-
Tags: None
-
What do you mean by that?Originally posted by sreenadh494how can u lock files in c
You want to lock the File using Password or want to give some privilege Access to specific Users.
What do you want?
And look, when you are doing File Handling in any Language then remember One thing what OS supported only you can do that.
By the way, What OS you are using?
Kind regards,
Dmjpro. -
If all parties can play by the same rules there exists an extremely easy fileOriginally posted by sreenadh494how can u lock files in c
locking scheme: suppose a file named "foo" is a shared resource.
1) Try to create a file named "foo.lck"; if this fails, the file "foo.lck" already exists
and is supposed to contain the PID of the process that created it.
2) if "foo.lck" didn't exist before, it exists now and write the process' PID to the
file and close it.
3) do whatever must be done with "foo" and remove "foo.lck" afterwards.
If step 1) failed (i.e. "foo.lck" existed already), check if the process that created it
still exists (its PID is in the .lck file). If the process isn't there, it must've died
prematurely; change the PID in the .lck file and continue with step 3). If the
process still exists it is working on file "foo" so the file is locked; all your process
can do is wait.
kind regards,
JosComment
Comment