in reply to Is file still open ?

Your LOCK_EX is probably failing because you only have the file opened for reading. Some operating systems require you to have the file open for writing to do LOCK_EX. But, as cdarke notes, locking won't tell you anything unless the other process is locking, too.

Some versions of Unix (and Linux) support the fuser command. FreeBSD has the fstat command. On some versions of Unix, there's no way to tell!

On most (I think all) Unixes, you can kill(pid, 0) to see if pid exists.

Replies are listed 'Best First'.
Re^2: Is file still open ?
by blazar (Canon) on May 15, 2006 at 13:18 UTC

    It's important to stress that the fuser command, just like Linux::Fuser (worth pointing out, anyway!) just inspects the /proc filesystem to find out. I.e. there's not a "direct" record of the processes that are holding a certain file open. The relation that is actually remembered is the inverse one...