需要top的源码并找到top与linux中/proc/目录的联系

发布于 2024-09-12 03:22:16 字数 291 浏览 2 评论 0原文

我想要 top 的源代码,但我在任何地方都找不到,我想要更多关于 /proc 目录到底包含什么的信息。我看到它有一系列标记为 1、2、3 4、.. 的文件夹。 ..并且在这些文件夹中似乎有一组一致的文件。我想知道这些是否是当前机器上运行的进程的目录。

我还想知道 TOP 到底是如何链接到这个文件夹的,因为我被告知进程是由 TOP 通过从这些目录中获取数据来监控的。我想知道哪个文件到底是从目录中获取特定进程的 CPU 使用率的 TOP 文件。如果它太复杂,如果您能指出我可以真正理解这一点的代码部分,那就太好了!

感谢您的帮助 舒维克

I wanted the source code for top which I could not find anywhere also, i wanted a little more information on what exactly does the /proc directory contain.y I have seen it have a series folders labeled 1, 2, 3 4, .... and in those folders there seem to be a consistent set of files. I was wondering if these are the directories for the processes running on the machine at the moment.

Also I wanted to know, how exactly TOP linked to this folder because I have been told that the processes are monitored by TOP, by fetching data from these directories. I would like to know which file exactly is TOP getting the CPU usage of the particular process from with the directory. If it's too complicated it would be great if you could just point me to the portion of the code where I could actually understand this from!

Thanks for your help
Shouvik

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

菊凝晚露 2024-09-19 03:22:16

procfs 基本上是系统和进程信息的文件抽象。

编号的文件夹当前正在运行具有与文件夹名称相关的 PID 的进程。


跟踪 top 或任何其他进程读取了哪些文件

strace -e open top

您可以使用树莓派

strace -e openat top

或更一般的 grep 来

strace top | grep open

,例如,U 获取输出

...
openat(AT_FDCWD, "/proc/7353/stat", O_RDONLY|O_LARGEFILE) = 8
openat(AT_FDCWD, "/proc/7353/statm", O_RDONLY|O_LARGEFILE) = 8
...

在这里您可以看到,top 打开了文件

/proc/[pid]/stat

其中包含有关进程的某些信息

The procfs is basically an file abstraction of system and process information.

The numbered folders are currently running processes with the folder name related PID.


You can trace which files where read out by top or any other process with

strace -e open top

or on raspberry

strace -e openat top

or more general with grep

strace top | grep open

for example, U get the ouput

...
openat(AT_FDCWD, "/proc/7353/stat", O_RDONLY|O_LARGEFILE) = 8
openat(AT_FDCWD, "/proc/7353/statm", O_RDONLY|O_LARGEFILE) = 8
...

Here you can see, that top opened the file

/proc/[pid]/stat

which contains certain information about the process

罪#恶を代价 2024-09-19 03:22:16

top 是 procps 的一部分,是的,这些数字是进程 ID。

top is part of procps, and yes, those numbers are process id's.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文