checking whether a file is locked

hi Guys,

I just wondering how I can check and ensure a file is not locked by another process. I need to modify a file using sed but I need to ensure that is not being modified by another process at the same time. Thanks.

Harby.

check the lsof command. Following command can be useful

lsof /home | grep connection.out

connection.out is the file that you need to check.

The trouble does not usually end there. How do you ensure the other process doesn't start modifying the file after you start modifying it? In order for locking to be helpful, all processes which access the file need to agree to a locking regime. Some OSes support mandatory locking but this is not portable across different U*x variants.