Here are some examples I have come across which are interesting and cool.
kill -9 `lsof -t -c sshd +f -- /dev/md2`
I want to kill all process which connects to my sshd, and are accessing raid /dev/md2. ensures no one is connected via ssh and is using the drive. I can then safely shut down sshd.
lsof -t -c java -a -u
this is a combination of
-c command
-a and
-u userid
-a and (another and)
+f file accessing raid disk.
lsof +f -- /var/log
everything accessing
you send a HUP to all process accessing /var/log, generally daemons accessing logs
kill -HUP `lsof +f -- /var/log`
lsof -i| grep LISTEN
all that your host is listening (-i is for tcp connections)
who is connected on port 6014
lsof -i:6014
lsof -i:22 -a -u
all those connected to port 22 and having
# lsof -i:22 -a -u *uid* | wc -l
14
# lsof -i:22 -u *uid* | wc -l
1228
remeber -t is for terse, it understands, that you only are interested in the process id.
100
even thoud *uid* user was accessing tons of files etc. he is running 100 process which are the handles to all those activity.
enjoy!