查看mysql线程
[root@localhost ~]# ps aux | grep mysqld
root 13699 0.0 0.0 103248 848 pts/3 S+ 10:12 0:00 grep mysqldroot 17891 0.0 0.0 106092 1388 ? S May30 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/mydata --pid-file=/opt/mydata/localhost.localdomain.pid
mysql 18334 0.0 2.8 14087904 951908 ? Sl May30 15:15 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/mydata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/opt/mydata/mysql_error.log --pid-file=/opt/mydata/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=38141
第一种方法:pstree -p ${pid}
[root@localhost ~]# pstree -p 18334|wc -l
54
第二种方法:top -p ${pid} 再按H 或者直接输入 top -bH -d 3 -p ${pid}
top -p 18334 再按H
Tasks: 11 total, 0 running, 11 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.1%sy, 1.1%ni, 98.5%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 32863040k total, 25042300k used, 7820740k free, 374396k buffers
Swap: 4094968k total, 0k used, 4094968k free, 20052216k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18347 mysql 20 0 13.4g 929m 6352 S 106.5 2.9 0:03.20 mysqld
18334 mysql 20 0 13.4g 929m 6352 S 0.0 2.9 0:01.49 mysqld
18338 mysql 20 0 13.4g 929m 6352 S 0.0 2.9 0:00.00 mysqld
18339 mysql 20 0 13.4g 929m 6352 S 0.0 2.9 0:05.52 mysqld
18340 mysql 20 0 13.4g 929m 6352 S 0.0 2.9 0:00.01 mysqld
top -bH -d 3 -p 18334
第三种方法:cat /proc/${pid}/status
[root@localhost ~]# cat /proc/18334/status
Name: mysqld
State: S (sleeping)
Tgid: 18334
Pid: 18334
PPid: 17891
TracerPid: 0
Uid: 27 27 27 27
Gid: 27 27 27 27
Utrace: 0
FDSize: 256
Groups: 27
VmPeak: 14144180 kB
VmSize: 14087904 kB
VmLck: 0 kB
VmHWM: 1058012 kB
VmRSS: 951908 kB
VmData: 14051988 kB
VmStk: 88 kB
VmExe: 8628 kB
VmLib: 3904 kB
VmPTE: 2276 kB
VmSwap: 0 kB
Threads: 55
SigQ: 0/256586
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000087007
SigIgn: 0000000000001006
SigCgt: 00000001800066e9
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: ffffffffffffffff
Cpus_allowed: ffffffff
Cpus_allowed_list: 0-31
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list: 0
voluntary_ctxt_switches: 79
nonvoluntary_ctxt_switches: 6
第四种方法:ps -mp <PID>
[root@localhost ~]# ps -mp 18334|wc -l
57
第五种方法:使用ps -eLf命令来查看线程信息
[root@localhost ~]# ps -eLf|grep 18334|wc -l
56
[root@localhost ~]# ps -Lf 18334|wc -l
56
第六种方法:
[root@localhost ~]# pstack
Usage: pstack <process-id>
[root@localhost ~]# pstack 18334
Thread 55 (Thread 0x7f0fe2d1c700 (LWP 18338)):
#0 0x000000340420b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x0000000000828256 in os_event_wait_low ()
#2 0x0000000000826e3d in os_aio_simulated_handle ()
#3 0x00000000007ea246 in fil_aio_wait ()
#4 0x0000000000788b88 in io_handler_thread ()
#5 0x0000003404207851 in start_thread () from /lib64/libpthread.so.0
#6 0x0000003403ee890d in clone () from /lib64/libc.so.6
Thread 54 (Thread 0x7f0d1af79700 (LWP 18339)):
#0 0x000000340420b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x0000000000828256 in os_event_wait_low ()
#2 0x0000000000826e3d in os_aio_simulated_handle ()
#3 0x00000000007ea246 in fil_aio_wait ()
#4 0x0000000000788b88 in io_handler_thread ()
#5 0x0000003404207851 in start_thread () from /lib64/libpthread.so.0
#6 0x0000003403ee890d in clone () from /lib64/libc.so.6
Thread 53 (Thread 0x7f0d1a578700 (LWP 18340)):
#0 0x000000340420b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x0000000000828256 in os_event_wait_low ()