Reputation: 11720
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
Upvotes: 5
Views: 11063
Reputation: 192
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
Upvotes: 2
Reputation: 118550
Upvotes: 10