linux 没有真正的线程, linux 上的线程是轻量级进程LWP.
The main difference between a light weight process (LWP) and a normal process is that LWPs share the same address space and other resources like open files etc. As some resources are shared so these processes are considered to be light weight as compared to other normal processes and hence the name light weight processes.
获取进程的线程情况
➜ ~ ps -Lf 1210
UID PID PPID LWP C NLWP STIME TTY STAT TIME CMD
mysql 1210 1 1210 0 10 4月17 ? Ssl 0:02 /usr/sbin/mariadbd
mysql 1210 1 1478 0 10 4月17 ? Ssl 3:24 /usr/sbin/mariadbd
mysql 1210 1 1479 0 10 4月17 ? Ssl 0:01 /usr/sbin/mariadbd
mysql 1210 1 1480 0 10 4月17 ? Ssl 0:00 /usr/sbin/mariadbd
mysql 1210 1 1481 0 10 4月17 ? Ssl 0:00 /usr/sbin/mariadbd
mysql 1210 1 1492 0 10 4月17 ? Ssl 0:00 /usr/sbin/mariadbd
mysql 1210 1 1566 0 10 4月17 ? Ssl 0:00 /usr/sbin/mariadbd
mysql 1210 1 9933 0 10 5月16 ? Ssl 0:00 /usr/sbin/mariadbd
mysql 1210 1 9937 0 10 5月16 ? Ssl 0:00 /usr/sbin/mariadbd
mysql 1210 1 13703 0 10 00:11 ? Ssl 0:00 /usr/sbin/mariadbd
➜ ~ ls -l /proc/1210/task/
总用量 0
dr-xr-xr-x 7 mysql mysql 0 5月 16 13:44 1210
dr-xr-xr-x 7 mysql mysql 0 5月 17 00:12 13703
dr-xr-xr-x 7 mysql mysql 0 5月 16 13:44 1478
dr-xr-xr-x 7 mysql mysql 0 5月 16 13:44 1479
dr-xr-xr-x 7 mysql mysql 0 5月 16 13:44 1480
dr-xr-xr-x 7 mysql mysql 0 5月 16 13:44 1481
dr-xr-xr-x 7 mysql mysql 0 5月 16 13:44 1492
dr-xr-xr-x 7 mysql mysql 0 5月 16 13:44 1566
dr-xr-xr-x 7 mysql mysql 0 5月 17 00:12 9933
dr-xr-xr-x 7 mysql mysql 0 5月 17 00:12 9937
➜ ~ top -Hp 1210
top - 00:18:19 up 29 days, 7:20, 1 user, load average: 0.21, 0.15, 0.13
Threads: 10 total, 0 running, 10 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1881996 total, 85684 free, 900112 used, 896200 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 791844 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1210 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:02.17 mariadbd
1478 mysql 20 0 1158504 130800 7732 S 0.0 7.0 3:24.05 mariadbd
1479 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:01.59 mariadbd
1480 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:00.00 mariadbd
1481 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:00.05 mariadbd
1492 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:00.00 mariadbd
1566 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:00.00 mariadbd
9933 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:00.22 mariadbd
9937 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:00.24 mariadbd
13703 mysql 20 0 1158504 130800 7732 S 0.0 7.0 0:00.00 mariadbd
➜ ~ pstree -p 1210
mariadbd(1210)─┬─{mariadbd}(1478)
├─{mariadbd}(1479)
├─{mariadbd}(1480)
├─{mariadbd}(1481)
├─{mariadbd}(1492)
├─{mariadbd}(1566)
├─{mariadbd}(13703)
├─{mariadbd}(15228)
├─{mariadbd}(15229)
├─{mariadbd}(15230)
└─{mariadbd}(15231)
ref
what-is-the-difference-between-lightweight-process-and-thread