简体   繁体   English

在系统调用中获取Cpu和内存信息

[英]Obtaining Cpu And Memory Information Inside a System Call

I am trying to achieve CPU and Memory usage information of current process, inside a system call. 我正在尝试在系统调用内实现当前进程的CPU和内存使用情况信息。 I can get current process name, pid and uid by using : 我可以通过使用以下命令获取当前进程名称,pid和uid:

current->comm //process name
current->pid //process id
current_uid() //uid

but that seems to be all.(I am using kernel 3.2.0-24-generic) 但这似乎就是全部。(我使用的是内核3.2.0-24-generic)

As I have seen from Memory usage of current process in C , reading(vfs_read) and parsing /proc/pid/status seems to be the only option to get memory and cpu usage. C中当前进程的内存使用情况可以看出,read(vfs_read)和解析/proc/pid/status似乎是获取内存和cpu使用情况的唯一选择。

Is there a better way to obtain this information, or am I on the right track? 有没有更好的方法来获取此信息,或者我走在正确的轨道上?

I also test my code as a kernel module first, since both system calls and kernel modules are running in kernel space. 我还首先将代码作为内核模块进行测试,因为系统调用和内核模块都在内核空间中运行。 Is that also bad approach? 这也是不好的方法吗?

current->mm is the place where all memory information is stored. current->mm是存储所有内存信息的位置。
current->mm->mmap is a list of memory mappings for the process, so you can iterate it and see what you find there. current->mm->mmap是该进程的内存映射列表,因此您可以对其进行迭代并查看在其中找到的内容。

current->utime and current->stime may be useful for getting CPU information. current->utimecurrent->stime对于获取CPU信息可能很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM