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/