Live data from Hacker News

A Unix Utility to Know About: lsof (2009)

catonmat.net

31–40 of 54 posts

Re: A Unix Utility to Know About: lsof (2009)

#33
post #25

Earlier quoted context omitted.

I am more a `killall ` guy.

Sometimes, I want something a little more murderous, so I tend to write this script on most systems I use: ps -ef | grep $1 | awk '{print "kill -9 " $2}' | sh Usually stored as /usr/local/bin/kll I've found it's very useful for killing specific Java programs without having to killall -9 java. (and, yeah, I should probably be using ps -efww instead of ps -ef, but old habits die hard... I've already got ps aliased to p…

You should try jps it's similar to ps but only lists java processes with their real names instead of just "java". It's included in pretty much every JDK.

Re: A Unix Utility to Know About: lsof (2009)

#34
post #2

`lsof` and `ps` have the most dense man pages I have ever tried to plow through, and that's causing me to use these tools only at a minimum.

I am guilty of using `ps|aux` for the sole purpose of answering this question: Is it (still) running ? edit: `ps aux|grep`, indeed. Silly me in the early hours of a rest day :).

Modern Linuxes have pgrep to help avoid the inevitable "lol, the grep process I fired will match" issue that results in having to filter that out as well with yet another program.

Re: A Unix Utility to Know About: lsof (2009)

#35

Earlier quoted context omitted.

I am guilty of using `ps|aux` for the sole purpose of answering this question: Is it (still) running ? edit: `ps aux|grep`, indeed. Silly me in the early hours of a rest day :).

>> I am guilty of using `ps|aux` What's wrong with doing that? I've been doing that for so long I don't know why I do it

Because there's so many process selectors and formatters in ps from procps?

  ps -C procname
  ps -p pid
  ps -u username
  ps -t ttyname
  ps -f [-w [-w]]
  ps -o output-format

Re: A Unix Utility to Know About: lsof (2009)

#36
lsof -i -n -P is a regular "reflex" command whenever I'm trying to figure out why a daemon I've just setup isn't responding to requests (immediately answers the questions: is it running? and, if yes, under what privs? and on what interface?).

That together with a dump of active iptables rules normally results in an immediate fix for 90% of "why can't I connect to X" problems :)

Re: A Unix Utility to Know About: lsof (2009)

#37

Earlier quoted context omitted.

I am guilty of using `ps|aux` for the sole purpose of answering this question: Is it (still) running ? edit: `ps aux|grep`, indeed. Silly me in the early hours of a rest day :).

Modern Linuxes have pgrep to help avoid the inevitable "lol, the grep process I fired will match" issue that results in having to filter that out as well with yet another program.

Good to know, I always just `ps aux | grep [j]ava`

Re: A Unix Utility to Know About: lsof (2009)

#38
post #2

`lsof` and `ps` have the most dense man pages I have ever tried to plow through, and that's causing me to use these tools only at a minimum.

Sometimes powerful tools require effort to understand. Lsof is absolutely something you should spend some real time grokking. In regard to ps you can memorize a few commands until something truly weird comes up since you will probably use other more specialized snapshotting and tracing tools for anything somewhat difficult to troubleshoot.

That's what I've been trying to tell people about Git, too. It's a powerful tool and it takes some effort to wrap your mind around it.

Re: A Unix Utility to Know About: lsof (2009)

#39

Earlier quoted context omitted.

For interactive use, I strongly recommend htop if you're still doing stuff like "ps aux | grep" and then "kill 84728". Htop is top on steroids: ncurses-based and very fast, has colors, threaded or flat process view, sorting by different criteria like cpu or ram use, searching for substring match in process name, interface to killing/signalling to selected process, etc. http://hisham.hm/htop/

I am more a `killall ` guy.

oh god i thought I was the only one

Re: A Unix Utility to Know About: lsof (2009)

#40
post #10

Earlier quoted context omitted.

You mean `ps aux | grep` which I am also guilty of using every time ? You might be interested in pgrep ( http://linux.die.net/man/1/pgrep ) as well.

For interactive use, I strongly recommend htop if you're still doing stuff like "ps aux | grep" and then "kill 84728". Htop is top on steroids: ncurses-based and very fast, has colors, threaded or flat process view, sorting by different criteria like cpu or ram use, searching for substring match in process name, interface to killing/signalling to selected process, etc. http://hisham.hm/htop/

For just viewing system information, I usually prefer glances to htop, although it can't signal. It has a curses interface and also includes network traffic, docker containers, disk IO, and it's nicely pluggable for both output formats (it can dump to CSV at interval as a daemon or while you're running it interactively (or something like graphite/influxdb if you have those)) as well as collection mechanisms (you write some python).
Post reply on HN