You are not logged in.
Hi, I have a homework where I have to write a program in C that emulates the top command by retrieving all information from the proc fs.
So I've found where I can get most of the information, however I'm stumped on where to get the info from the Tasks line. I know I can get the running processes either from /proc/stat or from /proc/loadavg. Does anyone know where I can find the total and number of sleeping processes?
I also have to output the current time, they didn't specify whether to use the c time functions or /proc so just wondering if that's displayed anywhere on proc?
Thanks for the help!
Offline
I assumed all these tools used the humble ps command (Example try ps -ef) If you cannot use that directly, then go look at the source code for the program and see how it does it
Have you read man 5 proc ??
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Unfortunately I don't think we're allowed to use the pf command. I went through the entire man for proc and couldn't find anywhere that gave the totals. I'm thinking I could try to go through every pid in /proc, but it seems like there should be a more direct way to get those totals directly from /proc.
Offline
Well, /proc/stat gives you a timestamp of the boot time, and /proc/uptime the uptime. From that, I guess you have the timestamp of the current time, if you need to get it from /proc. No idea about the number of processes though, other than looping from them all...
Offline
thanks! good call on that time... as for the processes I just went ahead and looped through, I guess I had to anyway to get the top 10 processes.
Offline
By default top does not include threads which are relevant for the things like ulimits... You can use ps -euH | wc -l for that...
Last edited by Leonid.I (2011-12-02 22:32:56)
Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd
Offline