Linux下查看進程線程數的方法

閱讀文本大概需要3分鐘。

0x01:ps -ef只打印進程,而ps -eLf會打印所有的線程

[root@centos6 ~]# ps -ef | grep rsyslogd
root      1470     1  0  2011 ?        00:01:13 /sbin/rsyslogd -c 4
root     29865 28596  0 22:45 pts/5    00:00:00 grep rsyslogd
[root@centos6 ~]# ps -eLf | grep rsyslogd
root      1470     1  1470  0    5  2011 ?        00:00:00 /sbin/rsyslogd -c 4
root      1470     1 28631  0    5 Mar04 ?        00:00:04 /sbin/rsyslogd -c 4
root      1470     1 28632  0    5 Mar04 ?        00:00:01 /sbin/rsyslogd -c 4
root      1470     1 28633  0    5 Mar04 ?        00:00:04 /sbin/rsyslogd -c 4
root      1470     1 28636  0    5 Mar04 ?        00:00:00 /sbin/rsyslogd -c 4
root     29867 28596 29867  0    1 22:45 pts/5    00:00:00 grep rsyslogd

rsyslogd這個進程有5個線程,所以ps -ef只有一行,而ps -eLf就有5行

ps -eLf各字段含義

  • UID:用戶ID

  • PID:process id 進程id

  • PPID: parent process id 父進程id

  • LWP:表示這是個線程;要麼是主線程(進程),要麼是線程

  • NLWP: num of light weight process 輕量級進程數量,即線程數量

  • STIME: start time 啓動時間

  • TIME: 佔用的CPU總時間

  • TTY:該進程是在哪個終端運行的;pts/0255代表虛擬終端,一般是遠程連接的終端;tty1tty7 代表本地控制檯終端

  • CMD:進程的啓動命令

0x02:top -H -p ${pid} 或者 top -p ${pid} 然後 shitf + H

0x03:cat /proc/${pid}/status  或者  ls /proc/${pid}/task

其中Threads後面跟的就是線程數

0x04:pstree -p ${pid}

0x05:ps -hH -p ${pid}

[root@localhost ~]# ps -hH -p 1414
 1414 ?        Ssl    0:00 /usr/sbin/rsyslogd -n
 1414 ?        Ssl    0:00 /usr/sbin/rsyslogd -n
 1414 ?        Ssl    0:00 /usr/sbin/rsyslogd -n

推薦閱讀

Spring Boot 最流行的 16 條實踐

SSM框架的面試常見問題

【分佈式】緩存穿透、緩存雪崩,緩存擊穿解決方案

阿里P7給出的一份超詳細 Spring Boot 知識清單

關注我每天進步一點點

你點的每個在看,我都認真當成了喜歡

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章