when i do a ps -efT
(where -T
= Show threads, possibly with SPID column.
), i see all the threads have the same PID, which is as expected.
myroot 24958 24958 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
myroot 24958 24959 7942 0 20:20 pts/12 00:00:11 java -jar myapp.jar
myroot 24958 24960 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
myroot 24958 24961 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
myroot 24958 24962 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
myroot 24958 24963 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
myroot 24958 24964 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
myroot 24958 24965 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
As it can be seen above, all the threads share/show the same PID 24958
.
Now When I do the same with top or htop, i am seeing differnt pid for each thread and this is bothering me. Is there a way to show the same PID for all the threads.
Below is the curtailed output for top -H -p 24958
(I am using top with -p, so i could explain and show the problem)
top - 21:42:44 up 9 days, 18:38, 0 users, load average: 0.00, 0.26, 0.82
Threads: 32 total, 0 running, 32 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.1 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 12542.5 total, 10135.3 free, 826.8 used, 1580.4 buff/cache
MiB Swap: 4096.0 total, 4096.0 free, 0.0 used. 11439.4 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
24958 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.00 java
24959 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:11.99 java
24960 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.43 GC Thread#0
24961 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.00 G1 Main Marker
24962 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.00 G1 Conc#0
--and few more threads.
When i use top -H
, i would not have any means to say which all threads belong to same Process unless I see same PID for all of them.
Any guidence on how to get the same PID for all the threads when using top (or htop. As I have observed, htop too has the same issue).
Given @user1686 answer to use TGID column. I am wondering what the PID for the thread is refering to.