What's the fastest way using lsof to find a single open file?

Posted by jjclarkson on Stack Overflow See other posts from Stack Overflow or by jjclarkson
Published on 2010-03-26T21:56:42Z Indexed on 2010/03/26 22:03 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

I'm trying to test a single file if it is open using lsof. Is there a faster way than this?

$result = exec('lsof | grep filename | wc -l');

if($result > 0) {
    //file is open
}

I'm thinking their must be a way to just test for one file if you know the filename. All I really need is a true or false.

© Stack Overflow or respective owner

Related posts about linux

Related posts about lsof