HOME        PACKAGES        SCRIPTS

The lsof Command

The lsof command shows all open files at a given point of time, and can be quite useful when you are trying to track down problems.

The following ipk definitely works on the sl5500:

http://quickening.zapto.org/ZaurusFeed/lsof_4.63_arm.ipk
 
http://sdjf.esmartdesign.com/files/lsof_4.63_arm.ipk

The current version (which may or may not work on the Zaurus, I have not tested) and official information about lsof is available via ftp:

Latest Revision: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/
 
Latest FAQ: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/FAQ
 
Latest man Page: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/lsof_man

And Menaie has compiled lsof for pdaX roms:

http://www.oesf.org/forums/index.php?showtopic=18415&view=findpost&p=160227
(If the above link does not work, use this one.)

The output from lsof can be quite long, but it can be filtered through grep to pare it down to what you need to look at.

For example, if I want to get a list of all open files on my CF card, I can enter the "lsof" command, and pipe it through grep so all I see is a list of the files on my CF card that are being used:

bash-2.05# lsof | grep cf
htmledito 2036 root cwd DIR 3,1 16384 480110 /usr/mnt.rom/cf/Jobstuff
bash-2.05#

If I want to see a listing for all the files open on both of my expansion cards, I would pipe the output through grep, so I can just look at the list all open files in /mnt/cf or /mnt/card:

bash-2.05# lsof | grep mnt | less
htmledito 2036 root cwd DIR 3,1 16384 480110 /usr/mnt.rom/cf/Jobstuff
htmledito 2036 root txt REG 60,1 234575 482634 /usr/mnt.rom/card/Programs/htmleditor
less 2084 root txt REG 60,1 87356 482633 /usr/mnt.rom/card/Programs/less
bash-2.05#

If I want to see what processes or commands are using my CF card, which is also called ttyS3 when it has a modem or WIFI card plugged in to the CF slot, I would enter the following command:

bash-2.05# lsof | grep ttyS3
pppd 2797 root 1u CHR 4,67 213 /dev/ttyS3
sh 2798 root 0u CHR 4,67 213 /dev/ttyS3
sh 2798 root 1u CHR 4,67 213 /dev/ttyS3
chat 2799 root 0u CHR 4,67 213 /dev/ttyS3
chat 2799 root 1u CHR 4,67 213 /dev/ttyS3
bash-2.05#

If I want to get a list of all the files being accessed by just one particular command, I can use the "-c" option. So, to see all the files being accessed by the kernel's cardmgr command, I would enter:

bash-2.05# lsof -c cardmgr
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
cardmgr 160 root cwd DIR 31,1 1024 10465 /home/etc/pcmcia
cardmgr 160 root rtd DIR 31,0 224 76 /
cardmgr 160 root txt REG 31,0 38892 2388864 /sbin/cardmgr
cardmgr 160 root mem REG 31,0 105908 1293808 /lib/ld-2.2.2.so
cardmgr 160 root mem REG 31,0 1152468 1349952 /lib/libc-2.2.2.so
cardmgr 160 root 0u CHR 253,0 6986 /home/tmp/fileVoWx7N (deleted)
cardmgr 160 root 1u CHR 253,1 7025 /home/tmp/fileYIqJes (deleted)
bash-2.05#

Revised October 7, 2010