question on files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreenadh494
    New Member
    • Aug 2007
    • 13

    question on files

    how can u lock files in c
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by sreenadh494
    how can u lock files in c
    What do you mean by that?
    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.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by sreenadh494
      how can u lock files in c
      If all parties can play by the same rules there exists an extremely easy file
      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,

      Jos

      Comment

      Working...