Excellent! I think I know Unix pretty well, but it would be great if someone had a directory of common use scenarios that one could look through, rather than using Google and wading through horrible forum posts...
If you feel that lsof is the swiss army knife of unix debugging, then you haven't done much serious unix debugging. Don't get me wrong, lsof is useful and even indispensable in some situations, but not exactly be-all-end-all.
DTrace fits that description much closer, even though its only available for OpenSolaris, OS X, I believe FreBSD has a port and Linux is getting one.
Thats the first thing that came to my mind when I read it as well. DTrace (and strace to a lesser extent) are the first things which come to mind whenever you've got to debug anything or atleast get a clue about whats going on in a runaway process.
I just sent him 'The Seasoned Schemer'. If anyone wants to send him 'The Reasoned Schemer', I'm sure he'd appreciate it, will be about $30 incl. int'l shipping. I know I really appreciate his posts. http://www.amazon.com/gp/registry/wishlist/QDKYO6OQUU4O?reve...
While you could send him The Reasoned Schemer (I already sold my copy), IMHO _The Art of Prolog_ is a far better book for learning the same material (logic programming, declarative programming, DSLs). Whatever you think about Prolog, it's as deep a book as SICP. Seriously wonderful. (O'Keefe's _The Craft of Prolog_ is a good follow-up.)
It's nice to have a hardbound copy of the newest edition, but the previous edition is available for comparatively cheap (US$6), and torrents of both seem to get around. FYI.
Warning: lsof can cause a kernel panic in OSX. I haven't tested it since leopard, but if you loop lsof continuously you'll hit it. There's some kind of race condition.
One of the reasons that advanced lsof usage isn't that common is that the Linux man page for it so dense, and a bunch of details you don't need to get started using it are in the first few pages. I've tried a number of times to get all the way through it and have never finished. Thankfully there are some examples at the end.
As long as everybody is learning about lsof this week, you might also want to check out a similar utility, fuser, which lists which processes are using a particular file.
It's really handy for some situations. For instance, if a process can't grab some port, you can use fuser to quickly determine which process grabbed it first.
[+] [-] jf|16 years ago|reply
[+] [-] nailer|16 years ago|reply
[+] [-] mattiss|16 years ago|reply
[+] [-] ars|16 years ago|reply
lsof doesn't really do anything for you if you know the pid already. (But it's great if you don't know the pid.)
Then, look through the list for your file, and copy the file descriptor just like in the article.
[+] [-] PStamatiou|16 years ago|reply
[+] [-] yan|16 years ago|reply
DTrace fits that description much closer, even though its only available for OpenSolaris, OS X, I believe FreBSD has a port and Linux is getting one.
edit: also see: strace, ltrace, gdb, truss
[+] [-] pkrumins|16 years ago|reply
Gonna write about strace in one of the next articles. And possibly also about dtrace in another article.
[+] [-] woadwarrior01|16 years ago|reply
[+] [-] nailer|16 years ago|reply
Linux does indeed have a port of dtrace, but it's not legal due to Sun's license.
[+] [-] clutchski|16 years ago|reply
[+] [-] lanstein|16 years ago|reply
[+] [-] silentbicycle|16 years ago|reply
It's nice to have a hardbound copy of the newest edition, but the previous edition is available for comparatively cheap (US$6), and torrents of both seem to get around. FYI.
[+] [-] pkrumins|16 years ago|reply
[+] [-] pkrumins|16 years ago|reply
I will now have all three books, reasoned, seasoned and little schemer. :)
Huge thanks to the person who bought the reasoned schemer!
Merry Christmas!
[+] [-] cliff|16 years ago|reply
[+] [-] spudlyo|16 years ago|reply
[+] [-] sammcd|16 years ago|reply
Port is in use 8003.
lsof -i :8003
Then I kill whatever process was on 8003. I do this a lot with my Django development if I didn't kill the server right the first time.
[+] [-] neilk|16 years ago|reply
http://linuxcommand.org/man_pages/fuser1.html
It's really handy for some situations. For instance, if a process can't grab some port, you can use fuser to quickly determine which process grabbed it first.