Live data from Hacker News

A Unix Utility to Know About: lsof (2009)

catonmat.net

11–20 of 54 posts

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

#11
post #4

What kernel functions does this command invoke to retrieve this information? How could I write my own version of lsof?

The stat() family functions for sure, BSD Sockets, user account, covering everything from "process environement" to "filesystem" functions.

"FAQ about lsof"[1] is very instructive.

[1] ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ

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

#13
Although a bit rare in my usage, I have found basic use of lsof quite useful when needed. I haven't even tried many command line options. The options it provides really seem comprehensive. I have also found similar tools on Windows (like WhoLockMe or Process Explorer) quite useful.

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

#15
post #10

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 :).

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/

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

#16
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/

I am more a `killall ` guy.

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

#17
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/

Agreed, htop is pretty awesome!

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

#18

Although a bit rare in my usage, I have found basic use of lsof quite useful when needed. I haven't even tried many command line options. The options it provides really seem comprehensive. I have also found similar tools on Windows (like WhoLockMe or Process Explorer) quite useful.

I'm not exposed to windows machines as much as i used to be, but yeah process explorer was pretty cool.

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

#19

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.

> I am more a `killall ` guy.

I've made a note to name the executable for my next daemon "humans".

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

#20
post #4

What kernel functions does this command invoke to retrieve this information? How could I write my own version of lsof?

If this sort of thing interests you, I cannot recommend https://www.nostarch.com/tlpi enough. The hardcover is worth every penny.
Post reply on HN