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

前端 未结 4 734
再見小時候
再見小時候 2021-01-05 16:13

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 &         


        
4条回答
  •  情话喂你
    2021-01-05 17:13

    Don't. The answer might change by the time you try to do anything with the result. Instead, try to do whatever you intended to do with the file and handle the "in use" error or "sharing violation".

提交回复
热议问题