file status question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hanhaner
    New Member
    • Mar 2007
    • 4

    #1

    file status question

    hi, everyone

    I am running many simulations, but need to update the same file from time to time.
    Before one simulation reach the file, i have to garantee the other simulations are not updating the file. So does anyone know how to check the file' status before reach it? And how to make a short pause if the other simulations are updating it?
    Thanks a lot!!!

    han
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    There is a standard way of doing this, it involves using a mutual exclusion semaphore (mutex).

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #3
      Originally posted by hanhaner
      hi, everyone

      I am running many simulations, but need to update the same file from time to time.
      Before one simulation reach the file, i have to garantee the other simulations are not updating the file. So does anyone know how to check the file' status before reach it? And how to make a short pause if the other simulations are updating it?
      Thanks a lot!!!

      han
      you can use fuser or lsof. I prefer lsof though. more powerful. an example
      Code:
      lsof -c "test.sh" #checks whether test.sh is being opened
      if test.sh not opened, lsof return a 1. so you can catch this output using $? in the shell.

      Comment

      Working...