fuser tells you what process is using an indicated filesystem object (ordinary file, device, etc.)
$ fuser /dev/dsp /dev/dsp: 8369
lsof lists all open files,is more detailed than fuser.
$ lsof /dev/dsp COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME mplayer 8406 alex 7w CHR 14,3 389 /dev/sound/dsp
Using -i 4 option will report all programs currently using IPv4 network, it is useful for watching the programs accessing the network and Internet resources.
$ lsof -i 4 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME btdownloa 2618 arky 3u IPv4 9524 TCP *:6886 (LISTEN) btdownloa 2618 arky 6u IPv4 9544 TCP dsl-KK-22.214.171.124.ttel.net:1539->cpc1-leed3-3-0-cust10.ldst.cable.ntl.com:59074 (ESTABLISHED)
fstat lists all open files.
The previous two commands (fuser and lsof) do not exist on all systems. The 4.3BSD-Tahoe system introduced the "fstat" command that is found on many *BSD systems. Unlike the previous two commands, it seems not to know the exact path of each file, but only what filesystem it is on?
Some options are:
-p PROCESSID show open files of this process -u USERNAME show open files of this user
Examples: Lists every open file by every user, including root! Pipe it into a pager.
$ fstat | less
Get the process ID of the running Bourne shell and then list the files it opened.
$ echo $$ 5283 $ fstat -p 5283 USER CMD PID FD MOUNT INUM MODE R/W DV|SZ ...
The init process always has ID of 1. List its open files. In this example it only opened one file somewhere on the / filesystem.
$ fstat -v -p 1 USER CMD PID FD MOUNT INUM MODE R/W DV|SZ root init 1 wd / 2 drwxr-xr-x r 512
- fstat, freebsd.org