

Swiss Army Knife of Unix Debugging: lsof - pkrumins
http://www.catonmat.net/blog/unix-utilities-lsof/

======
jf
Don't forget that you can use lsof to undelete files (provided that at least
one process still has the file open):
<http://www.linux.com/archive/articles/58142>

~~~
mattiss
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...

~~~
Estragon
Not completely sure what you're asking for, here, but Command Line Fu might be
in the ball park:

<http://www.commandlinefu.com/commands/browse>

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

edit: also see: strace, ltrace, gdb, truss

~~~
nailer
You'd use SystemTap for kernel-level tracing and breakpoint debugging on
Linux. Check the wiki for a bunch of useful pre-cut tap files.

Linux does indeed have a port of dtrace, but it's not legal due to Sun's
license.

~~~
sp332
OS X has a port of DTrace, so I doubt licensing is a big issue.

~~~
tedunangst
What he meant to say is that it's not legal because of Linux's license.

~~~
nailer
Not at all. The GPL is a much older license than the Sun CDDL, which mainly
seems to have been created to stop any useful code from Solaris entering
Linux.

------
lanstein
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...](http://www.amazon.com/gp/registry/wishlist/QDKYO6OQUU4O?reveal=unpurchased&filter=all&sort=priority&layout=standard&x=6&y=13)

~~~
silentbicycle
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.

~~~
pkrumins
I had never heard about "The Art of Prolog". Gonna check it out!

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

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

------
sammcd
I run into this a lot.

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

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

