加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Linux查看进程/子进程/线程信息

(2018-09-11 13:43:09)
分类: my_work

查看进程ID:

[root@QLB data]# ps -ef | grep mysqld | grep -v "grep"

root      3988     1  0 Feb20       00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql

mysql     4256  3988  2 Feb20       01:08:10 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql

 

查看某个进程的所有线程:

[root@QLB data]# ps mp 4256 -o THREAD,tid
USER     %CPU PRI SCNT WCHAN  USER SYSTEM   TID
mysql     2.5     - -                -
mysql     0.0  24    - -             4256
mysql     0.0  14    - futex_        4258
mysql     0.0  23    - futex_        4259
mysql     0.0  24    - futex_        4260
mysql     0.0  24    - futex_        4261
mysql     0.0  23    - futex_        4262
mysql     0.0  24    - futex_        4263
mysql     0.0  24    - futex_        4264
mysql     0.0  24    - futex_        4265
mysql     0.0  24    - futex_        4266
mysql     0.0  24    - futex_        4267
mysql     0.0  24    - futex_        4269
mysql     0.0  24    - futex_        4270
mysql     0.0  21    - futex_        4271
mysql     0.0  24    - futex_        4272
mysql     0.0  20    - -             4273

 

查看进程树:

[root@QLB data]# pstree -p 3988
mysqld_safe(3988)───mysqld(4256)─┬─{mysqld}(4258)
                                 ├─{mysqld}(4259)
                                 ├─{mysqld}(4260)
                                 ├─{mysqld}(4261)
                                 ├─{mysqld}(4262)
                                 ├─{mysqld}(4263)
                                 ├─{mysqld}(4264)
                                 ├─{mysqld}(4265)
                                 ├─{mysqld}(4266)
                                 ├─{mysqld}(4267)
                                 ├─{mysqld}(4269)
                                 ├─{mysqld}(4270)
                                 ├─{mysqld}(4271)
                                 ├─{mysqld}(4272)
                                 └─{mysqld}(4273)

 

查看某个进程的状态信息:

[root@QLB data]# cat /proc/4256/status
Name: mysqld
State: S (sleeping)
SleepAVG: 98%
Tgid: 4256
Pid: 4256
PPid: 3988
TracerPid: 0
Uid: 102 102 102 102
Gid: 501 501 501 501
FDSize: 512
Groups: 501
VmPeak:   410032 kB
VmSize:   410032 kB
VmLck:        0 kB
VmHWM:   204356 kB
VmRSS:   199920 kB
VmData:   372332 kB
VmStk:       88 kB
VmExe:     8720 kB
VmLib:     3544 kB
VmPTE:      608 kB
StaBrk: 0ed3d000 kB
Brk: 136ae000 kB
StaStk: 7fff2268a570 kB
Threads: 16
SigQ: 0/69632
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000087007
SigIgn: 0000000000001006
SigCgt: 00000001800066e9
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
Cpus_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000000f
Mems_allowed: 00000000,00000001

 

Linux User’s Manual上的ps的使用例子:
1. To see every process on the system using standard syntax:
ps -e
ps -ef
ps -eF
ps -ely

2. To see every process on the system using BSD syntax:
ps ax
ps axu

3. To print a process tree:
ps -ejH
ps axjf

4. To get info about threads:
ps -eLf
ps axms

5. To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM
6. To see every process running as root (real & effective ID) in user format:
ps -U root -u root u

7. To see every process with a user-defined format:
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -eopid,tt,user,fname,tmout,f,wchan

8. Print only the process IDs of syslogd:
ps -C syslogd -o pid=

9. Print only the name of PID 42:
ps -p 42 -o comm=

Posted in Linux/Unix.

Comments are closed.

首先,得到进程的pid:
ps -ef | grep process_name | grep -v “grep” | awk ‘{print $2}’

查看进程的所有线程
# ps mp 6648 -o THREAD,tid
USER %CPU PRI SCNT WCHAN USER SYSTEM TID
root 0.0 – - – - – -
root 0.0 24 – - – - 6648
root 0.0 21 – - – - 6650
root 1.0 24 – - – - 14214
root 0.0 23 – futex_ – - 14216
root 0.0 22 – 184466 – - 15374
root 0.0 23 – 184466 – - 15376
root 0.0 23 – 184466 – - 15378
root 0.0 23 – 184466 – - 15380
root 0.0 23 – 184466 – - 15392
root 0.0 23 – 184466 – - 15394
root 0.0 23 – 184466 – - 15398

查看所有子进程
# pstree -p 6648
agent_executor(6648)─┬─tar(15601)───gzip(15607)
├─{agent_executor}(6650)
├─{agent_executor}(14214)
├─{agent_executor}(14216)
├─{agent_executor}(15374)
├─{agent_executor}(15376)
├─{agent_executor}(15378)
├─{agent_executor}(15380)
├─{agent_executor}(15392)
├─{agent_executor}(15394)
└─{agent_executor}(15398)

查看/proc/pid/status可以看到一些进程的当前状态:
Name: bash
State: S (sleeping)
SleepAVG: 98%
Tgid: 11237
Pid: 11237
PPid: 11235
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 256
Groups: 0 1 2 3 4 6 10
VmPeak: 66260 kB
VmSize: 66228 kB
VmLck: 0 kB
VmHWM: 1684 kB
VmRSS: 1684 kB
VmData: 456 kB
VmStk: 88 kB
VmExe: 712 kB
VmLib: 1508 kB
VmPTE: 68 kB
StaBrk: 008c3000 kB
Brk: 011b1000 kB
StaStk: 7fff8b728170 kB
Threads: 1
SigQ: 1/30222
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000010000
SigIgn: 0000000000384004
SigCgt: 000000004b813efb
CapInh: 0000000000000000
CapPrm: 00000000fffffeff
CapEff: 00000000fffffeff
Cpus_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000003
Mems_allowed: 1

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有