Fun with fuser on Solaris 10
I was writing a Perl program to help unmount a bunch of filesystems. I provide a list of mount points and get back a list of process IDs to be killed.
On Linux, the best way to do this is lsof -t. This straight up returns a list of process IDs that are using a filesystem. Absolutely lovely.
On Solaris 10, the only way to do this is by using fuser. The output of fuser contains the mountpoint that you provided, along with a list of process IDs followed by a letter which acts as an identifier, explaining what the process is doing. Output looks something like this:
server: root # fuser /tmp/
/tmp/: 3902c 15179c
Okay, cool. Bit messy, but I know what I’ll do. If I can find a number followed by a letter, I’ll just take the number and add it to my list. Some back-references will do the trick nicely:
Looks good! But wait — after running it, all I got was the stuff that I didn’t want!
server: root # /tmp/fuser-script.pl /tmp
/tmp: ccc
What? Well, after some messing around I figured out what was up:
server: root # fuser /tmp 1>/dev/null
/tmp: cc
server: root # fuser /tmp 2>/dev/null
3365 15179
fuser appears to print the process IDs out on STDOUT and everything else on STDERR. Gee, thanks for telling me that, man fuser.
Oh wait, you didn’t.