리눅스에서는 Thread가 기본적으로 표시되지 않습니다.
PS 명령에서 thread를 보는 방법은 다음과 같습니다.

- THREAD DISPLAY
-H : thread를 process처럼 보여준다.
-L : thread를 보여준다. LWP(thread id)와 NLWP(number of threads) 칼럼과 함께
-T : thread를 보여준다. SPID 칼럼과 함께 (SPID = LWP, TID)
-m: 프로세스 다음에 thread를 보여준다.

PS 명령어로 thread에 대한 정보를 보려고 할 때, 아래 옵션을 사용하면 됩니다.

ps -eT -o euser,pid,vsz,rss,comm | grep http
ps -eL -o euser,pid,vsz,rss,comm | grep http

ps -em -o euser,pid,ppid,lwp,vsz,rss,comm | grep wasadmt | more
ps -eL -o euser,pid,ppid,lwp,vsz,rss,comm | grep wasadmt | more
ps -eH -o euser,pid,ppid,lwp,vsz,rss,comm | grep wasadmt | more
ps -eT -o euser,pid,ppid,lwp,vsz,rss,comm | grep wasadmt | more


참고로 TOP 명령어에서는 H 키를 누르면 thread가 표시됩니다.




The classical tool top shows processes by default but can be told to show threads with the H key press or -H command line option. There is also htop, which is similar to top but has scrolling and colors; it shows all threads by default (but this can be turned off). ps also has a few options to show threads, especially H and -L.

There are also GUI tools that can show information about threads, for example qps (a simple GUI wrapper around ps) or conky (a system monitor with lots of configuration options).

For each process, a lot of information is available in /proc/12345 where 12345 is the process ID. Information on each thread is available in /proc/12345/task/67890 where 67890 is the kernel thread ID. This is where pstop and other tools get their information.


*****************************************************************************************************************************************


Hello Lazer, I would like to make it clear that each answer here is providing you with exactly what you have specified, a list of all threads associated with a process, this maybe be unobvious in htop as it by defaults lists all threads on the system not just the process, but top -H -p <pid> works better for example:

top - 00:03:29 up 3 days, 14:49,  5 users,  load average: 0.76, 0.33, 0.18
Tasks:  18 total,   0 running,  18 sleeping,   0 stopped,   0 zombie
Cpu(s): 22.6%us,  5.7%sy,  4.2%ni, 66.2%id,  0.8%wa,  0.5%hi,  0.1%si,  0.0%st
Mem:   2063948k total,  1937744k used,   126204k free,   528256k buffers
Swap:  1052220k total,    11628k used,  1040592k free,   539684k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
30170 daniel    20   0  371m 140m 107m S 10.0  7.0   0:31.37 source:src    
30066 daniel   -90   0  371m 140m 107m S  2.0  7.0   0:07.87 clementine               
30046 daniel    20   0  371m 140m 107m S  0.0  7.0   0:32.05 clementine                  
30049 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.03 clementine                          
30050 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.31 clementine                          
30051 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30052 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30053 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30054 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.03 clementine                          
30055 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30056 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30057 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.04 clementine                          
30058 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30060 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.16 clementine                          
30061 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30062 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30064 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine                          
30065 daniel    20   0  371m 140m 107m S  0.0  7.0   0:00.00 clementine

as a side note the thread with -90 is actually a realtime thread

but

There's also another option which is true CLI ps -e -T | grep <application name or pid>

  • -e show's all processes
  • -T lists all threads
  • | pipes the output to the next command
  • grep this filters the contents

here's an example:

$ ps -e -T | grep clementine
  PID  SPID TTY          TIME CMD       # this is here for clarity
30046 30046 pts/2    00:00:17 clementine
30046 30049 pts/2    00:00:00 clementine
30046 30050 pts/2    00:00:00 clementine
30046 30051 pts/2    00:00:00 clementine
30046 30052 pts/2    00:00:00 clementine
30046 30053 pts/2    00:00:00 clementine
30046 30054 pts/2    00:00:00 clementine
30046 30055 pts/2    00:00:00 clementine
30046 30056 pts/2    00:00:00 clementine
30046 30057 pts/2    00:00:00 clementine
30046 30058 pts/2    00:00:00 clementine
30046 30060 pts/2    00:00:00 clementine
30046 30061 pts/2    00:00:00 clementine
30046 30062 pts/2    00:00:00 clementine
30046 30064 pts/2    00:00:00 clementine
30046 30065 pts/2    00:00:00 clementine
30046 30066 pts/2    00:00:03 clementine
$

each of these has the same PID so you know they are in the same process

please don't hesitate to ask more questions


ps -e -T | sed -n '1p; /clementine/p;'


/usr/bin/pstree $PID



+ Recent posts