linuxlsof

Difference between lsof -c name and lsof | grep ^name?


I'm trying to figure out whether I have a leak in file descriptors using lsof. The -c option to lsof is defined as:

If that's true then why do these two commands report different numbers?

$ lsof -c gunicorn | wc -l
589
$ lsof | grep ^gunicorn | wc -l
29154

Solution

  • The default lsof will output the the main process and the threads with a TID (Thread ID) However, if you if you filter the output using a -c, only process opened files are listed, without TID. You will notice this if you look at the headers of the two outputs, ´lsof -c´ output is missing the TID column.

    You can read more about TID in the man page.