Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check open file without lsof

Tags:

android

lsof

In linux, I use lsof to check the file is opened by which process. I have an android device, but no lsof command. Is it possible to find which process open the specific file ?

I will use it to verify the MediaPlayer hold a fd, but it should be closed.

like image 861
qrtt1 Avatar asked May 29 '12 09:05

qrtt1


People also ask

What can I use instead of lsof?

The best alternative is htop, which is both free and Open Source. Other great apps like lsof are vtop, Resource Monitor, Sysdig and Ctop. lsof alternatives are mainly Process Monitoring Tools but may also be Process Management Tools or System Information Utilities.

Which command is used to identify open files?

The open source lsof command is also useful for providing information about files opened by processes, and files opened under specific user accounts.

How can you tell if a file is open in Linux?

The command lsof -t filename shows the IDs of all processes that have the particular file opened. lsof -t filename | wc -w gives you the number of processes currently accessing the file.


2 Answers

Poor man's lsof is to execute

ls -l  /proc/[process id]/fd

Still, you need to be root.

like image 155
johsin18 Avatar answered Sep 21 '22 13:09

johsin18


Thanks mike jones and Joqn for the tip with poor man's lsof. I used it in the following on busybox (synology nas) to list the fd directories grouped under each process:

  for p in [0-9]*; do ls -l /proc/$p/fd ;done 
like image 45
rob451 Avatar answered Sep 20 '22 13:09

rob451