首先实用sar
运行测试程序之前
# sar -w 2
Linux 5.4.0-26-generic (rlk) 2022年05月28日 _x86_64_ (4 CPU)
06时13分05秒 proc/s cswch/s
06时13分07秒 0.00 211.50
06时13分09秒 0.00 257.50
06时13分11秒 0.00 230.00
06时13分13秒 0.00 175.50
运行测试程序之后
06时13分25秒 386.00 9949.00
06时13分27秒 403.50 10759.50
06时13分29秒 400.50 10353.00
06时13分31秒 405.50 10423.50
06时13分33秒 414.50 10687.00
06时13分35秒 431.00 10841.50
06时13分37秒 420.50 11696.50
06时13分39秒 432.50 10746.50
-w的含义详见 man sar
-w Report task creation and system switching activity.
proc/s
Total number of tasks created per second.
cswch/s
Total number of context switches per second.
proc是子进程创建的频率
然后用下述命令查看是什么子进程被频繁创建
# execsnoop-bpfcc
PCOMM PID PPID RET ARGS
sh 628915 613382 0
sh 628916 613374 0
stress 628918 628915 0 /usr/local/bin/stress -t 1 -d 1
stress 628919 628916 0 /usr/local/bin/stress -t 1 -d 1
sh 628917 613373 0
sh 628922 613396 0
stress 628923 628917 0 /usr/local/bin/stress -t 1 -d 1
stress 628925 628922 0 /usr/local/bin/stress -t 1 -d 1
sh 628924 613387 0
stress 628928 628924 0 /usr/local/bin/stress -t 1 -d 1
sh 628930 613374 0
stress 628932 628930 0 /usr/local/bin/stress -t 1 -d 1
由此可见,大量的stress子进程被频繁创建
# pstree | grep stress
| | `-xxx---sh---stress
由此可见, stress是由父进程xxx创建
参考
bcc工具之execsnoop
https://blog.youkuaiyun.com/qq_33894122/article/details/108186999