Linux 进程及其子进程读取/写入的总字节数
我想打印 Linux 进程读/写的总字节数。例如,我运行
gcc -c a.c
并想查看 GCC(包括其子级)总共向 Linux 内核请求了多少字节,以及它们向内核发送了多少字节。
该问题的不完整解决方案是:
/proc/PID/io
中的字段rchar
和wchar
显示读/写的数量到目前为止的字节数。它不考虑子进程。一旦进程终止,它就会丢失。诸如
strace
之类的工具可用于打印进程及其子进程的系统调用(例如:read
、write
syscalls),但无法聚合读/写的字节数。
如何打印Linux进程及其子进程读/写的总字节数?
I would like to print the total number of bytes read/written by a Linux process. For example, I run
gcc -c a.c
and would like to see how many bytes in total did GCC, including its children, request from the Linux kernel and how many bytes they sent to the kernel.
Incomplete solutions to this problem are:
The fields
rchar
andwchar
in/proc/PID/io
show the number of read/written bytes so far. It does not account for child processes. It is lost as soon as the process terminates.A tool such as
strace
can be used to print out the syscalls of a process and its children (such as:read
,write
syscalls), but it is unable to aggregate the number of bytes read/written.
How to print the total number of bytes read/written by a Linux process and its child processes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点 awk,strace 就是你想要的。
为您提供读取和写入系统调用的日志。现在您可以获取此日志并对最后一列进行求和,如下所示
您可能不想更改 grep 以仅匹配行开头的读取。
A little awk, and strace is what you want.
gives you a log of the read and write syscalls. Now you can take this log and sum the last column like this
You might wan't to change the grep to match only a read at the beginning of the line.
你可以看一下iotop,这是一个类似top的工具,可以显示磁盘消耗情况每个进程的数据(实时以及总的写入和读取)。
编辑:
您还可以检查sysstat,它看起来对于监控Linux机器非常强大。根据文档:
在这里您将找到 sar 的一些使用示例(主要命令sysstat 包的)。
You could take a look to iotop, it is a top-like tool that can display the disk consumption of each process (real time and total written and read).
EDIT:
You can also check sysstat which looks very powerfull for monitoring a linux box. According to the documentation :
And here you will find some examples of usage of sar (the main command of the sysstat package).