3

The ps command can be done in terminal to view information about a process. For example,

#list processes
ps aux
#with executable paths
ps -ef
#path for a specific process
ps -p [pid]

However, if a process is large, it may be necessary to isolate what individual threads are doing. For example, kernel_task. The command sudo dtruss -ap [pid] is not optimal because it requires turning off system resource protection. Is there a way to find ps information about threads without turning off system resource protection?

Thanks

1 Answer 1

4

The "-T" option for the ps command enables thread views.

# ps -T -p <pid>

For example, to list the threads for the following java process:

# ps -ef | grep 97947
deploy   97947 97942  1 00:51 ?       00:13:51 java

Alternatively, you can use top which can show a real-time view of individual threads. To enable thread views in the top output, invoke top with "-H" option. This will list all Linux threads. You can also toggle on or off thread view mode while top is running, by pressing 'H' key.

top - 14:43:25 up 6 days,  5:40,  2 users,  load average: 0.87, 0.33, 0.22
Threads: 684 total,   1 running, 683 sleeping,   0 stopped,   0 zombie
%Cpu(s):  6.3 us,  4.0 sy,  0.0 ni, 89.6 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  7910136 total,   384812 free,  1603096 used,  5922228 buff/cache
KiB Swap:  8388604 total,  8239100 free,   149504 used.  5514264 avail Mem

Note how in the example above the number of threads on the system is listed.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.