Given the wide use of Linux threads, how do we look at the thread ID that a process has?
Now many services are designed for the main process---child process--thread (e.g. Mysql,varnish)
The main process is responsible for listening to connections on the network and sending the connections to child process child process derived threads to process these threads
MySQL (Parent process 460, child process 863)
1 460 425 333? -1S0 0:xx/bin/SH/usr/local/mysql/bin/mysqld_safe--datadir=/storage/mysql/backup--pid-file=/Storag460 863 425 333? -1Sl - +: the\_/usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql--datadir=/storage/mysql/backup
1, PS
-T Show threads, possibly with SPID column
[Email protected] ~]#PS-t-p863PID SPID TTY time CMD863 863?xx:xx:xxmysqld863 865?xx:xx:Wuyimysqld863 866?xx: on: -mysqld863 867?xx:xx: -mysqld863 868?xx:xx: -mysqld863 869?xx:xx: themysqld863 870?xx:xx: themysqld863 871?xx:xx: -mysqld863 872?xx:xx: themysqld863 873?xx:xx:Wuyimysqld863 874?xx:xx: -mysqld863 876?xx:Geneva: Amysqld863 877?xx: -: Wumysqld863 878?xx:xx: +mysqld863 879?xx:xx:xxmysqld863 882?xx:xx:xxmysqld863 887?xx:xx:xxmysqld863 2408?xx:xx:xxmysqld863 2428?xx:xx:xxMysqld
We can see that the first line of the thread that the child process 863 derives from, SPID 863 is the main thread (we know that the main thread is the process itself)
2. Top
-h:threads Toggle
Starts top with the last remembered ' H ' state reversed. When this toggle are on, all individual threads'll be dis-
Played. Otherwise, top displays a summation of all threads in a process.
Top-h-P 863
PID USER PR NI VIRT RES SHR S%cpu%MEM time+COMMAND872Mysql - 0741m 56m4972S0.3 5.7 0:49.11mysqld876Mysql - 0741m 56m4972S0.3 5.7 4:22.76mysqld863Mysql - 0741m 56m4972S0.0 5.7 0:00.06mysqld865Mysql - 0741m 56m4972S0.0 5.7 0:51.65mysqld866Mysql - 0741m 56m4972S0.0 5.7 1:14.77mysqld867Mysql - 0741m 56m4972S0.0 5.7 0:58.15mysqld868Mysql - 0741m 56m4972S0.0 5.7 0:50.26mysqld869Mysql - 0741m 56m4972S0.0 5.7 0:49.88mysqld870Mysql - 0741m 56m4972S0.0 5.7 0:52.48mysqld871Mysql - 0741m 56m4972S0.0 5.7 0:50.83mysqld873Mysql - 0741m 56m4972S0.0 5.7 0:51.90mysqld874Mysql - 0741m 56m4972S0.0 5.7 0:48.10mysqld877Mysql - 0741m 56m4972S0.0 5.7 7:55.01mysqld878Mysql - 0741m 56m4972S0.0 5.7 0:19.84mysqld879Mysql - 0741m 56m4972S0.0 5.7 0:00.00mysqld882Mysql - 0741m 56m4972S0.0 5.7 0:00.00mysqld887Mysql - 0741m 56m4972S0.0 5.7 0:00.58mysqld2408Mysql - 0741m 56m4972S0.0 5.7 0:00.00mysqld2428Mysql - 0741m 56m4972S0.0 5.7 0:00.06Mysqld
3, Pstree
[Email protected] ~]# pstree-aup-h460Mysqld_safe (460)---mysqld (863, MySQL)-+-{mysqld} (865) |-{MYSQLD} (866) |-{MYSQLD} (867) |-{MYSQLD} (868) |-{MYSQLD} (869) |-{MYSQLD} (870) |-{MYSQLD} (871) |-{MYSQLD} (872) |-{MYSQLD} (873) |-{MYSQLD} (874) |-{MYSQLD} (876) |-{MYSQLD} (877) |-{MYSQLD} (878) |-{MYSQLD} (879) |-{MYSQLD} (882) |-{MYSQLD} (887) |-{MYSQLD} (2408) `-{MYSQLD} (2428)
Linux View Thread ID (SPID) for a process