进程占用过高cpu的排查

本文介绍了Linux系统中查看性能和进程相关信息的工具与方法。如用vmstat查看系统负载,ps列出高CPU使用率进程、查看进程线程及资源,lsof查看进程打开的文件等,还介绍了ioctl参数和查CPU中断数的方法,部分操作结合了awk命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.
vmstat工具,可以查看系统级别的负载情况,包括进程、内存、IO、CPU、系统调用等等
用法:vmstat [options] [delay [count]]
第一行是自上次reboot之后的平均负载,之后的输出是该delay时间段内的增量值(比如中断数、系统调用数等,但像是内存、cpu负载这些参数等就还是实时值)
输出示例:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 8 266056 130176 1352704 0 0 294 35 665 1552 8 4 86 2 0
1 0 8 264356 130216 1354632 0 0 0 184 1958 2605 1 4 93 2 0
0 0 8 264248 130216 1354660 0 0 0 0 781 1364 1 1 99 0 0
参数解释:
Procs
r: The number of runnable processes (running or waiting for run time).
b: The number of processes in uninterruptible sleep.

Memory
swpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)

Swap
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).

IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).

System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.

CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
2.
使用ps命令列出cpu使用率最高的几个进程:
ps -eo pid,user,pcpu,command --sort=-pcpu | head -n 10
3.
查看进程的线程和线程占用的资源:
ps -Lp 1567284
top -H -p 1567284
4.
查看进程打开了哪些文件、套接字、设备、目录等:
lsof -n -p 403601 参数-n是不进行dns解析,-p指示进程号
5.
int ioctl(int fd, ind cmd, …)参数:
fd是用户程序打开设备时使用open函数返回的文件标示符,cmd是用户程序对设备的控制命令,至于后面的省略号,那是一些补充参数,一般最多一个,这个参数的有无和cmd的意义相关
6.
查cpu的中断数:
cat /proc/interrupts | awk '{print $25,$22,$29,$50}'

 

参考:
https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/investigating_high_cpu_for_java_processes_on_linux_aix_hpux_solaris_windows_identifying_the_suspects?lang=en
https://www.tecmint.com/strace-commands-for-troubleshooting-and-debugging-linux/
https://www.howtoforge.com/linux-strace-command/

转载于:https://www.cnblogs.com/qxxnxxFight/p/11076687.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值