fuser: you are helpful
Today I met a unix utility I didn’t know of. Not because it was new, I simply didn’t know it. Found it useful so I’m blogging about it before I forget it ![]()
fuser tells you which processes are using some file or socket. Interesting when you try to disconnect something but it keeps insisting someone is still using it. Another occasion is when VMWare is unable to activate sound because /dev/dsp is busy and you *need* to watch this football match in your virtual windows machine with sound (that was my case :P) .
In case you are an action guy and only knowing who uses it doesn’t feel good enough, you can signal those processes. And I’m sure the best signal is -9 so use -k flag and kill ‘em all.
Just two restrictions, from its Linux manpage:
fuser may only be able to gather partial information unless run with privileges. As a consequence, files opened by processes belonging to other users may not be listed and executables may be classified as mapped only.
fuser cannot report on any processes that it doesn’t have permission to look at the file descriptor table for. The most common time this problem occurs is when looking for TCP or UDP sockets when running fuser as a non-root user. In this case fuser will report no access
Of course these both could be bypassed activating SUID bit on fuser, but that doesn’t sound like a good idea from security point of view.