0

When i use -p $PID on lsof i get only the immediate thread of the process. why and how to work with threads and lsof effectively?

sudo lsof -p 5344 > lsof-p5344.log
sudo lsof | grep  '\<5344\>' > lsofgrep5344.log

$ wc -l lsof*5344.log
  1,120,208 lsofgrep5344.log
      2,166 lsof-p5344.log

Those are lines for the exact process. This is not about children process. Here I am using awk to filter by exactly the process PID numbers (Second column of lsof output) being on field two of the output.

$ cat lsof-p5344.log  | awk '{print $2}' | grep '^5344$' | wc -l
2,165

$ cat lsofgrep5344.log  | awk '{print $2}' | grep '^5344$' | wc -l
1,120,207

now if i filter by the first column "COMMAND", then i see different threads of the java application, while the lsof -p one will only show the main thread (e.g. "COMMAND=java_daemon"), the lsof | grep will have many (e.g. "COMMAND=pool123, JMX, Java2D, Quartz, etc", with "PID" all equal to 5344)

1

1 Answer 1

1

On my system, lsof -k displays thread numbers. But I guess the ressources (files, memory maps...) are allocated for the whole process (A file opened by a thread can be used by an other), then digging to the thread doesn't seem pertinent.

On my Linux system, I create a thread which terminates immediately after opening a file. lsof continues to see the file while the thread which had opened it is not there anymore.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .