Showing posts with label howto lsof. Show all posts
Showing posts with label howto lsof. Show all posts

Monday, February 28, 2011

lsof is magical

Here is a link, which is kind of primer for lsof, since it has examples.

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 -a +f -- /dev/md2
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 remember if you do not specify -a, it becomes an or and that would mean any thing accessed by

# 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.

# lsof -t -i:22 -u *uid* | wc -l
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!




VIM issues with powerline

What to do if you get this annoying issue - vi requirements.txt ...