You are not logged in.

#1 2011-12-02 16:21:23

aiguofer
Member
Registered: 2011-10-09
Posts: 32

Finding info about current tasks in /proc

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

#2 2011-12-02 17:48:16

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,326

Re: Finding info about current tasks in /proc

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 smile

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

#3 2011-12-02 18:23:29

aiguofer
Member
Registered: 2011-10-09
Posts: 32

Re: Finding info about current tasks in /proc

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

#4 2011-12-02 21:10:36

jjacky
Member
Registered: 2011-11-09
Posts: 347
Website

Re: Finding info about current tasks in /proc

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

#5 2011-12-02 21:23:43

aiguofer
Member
Registered: 2011-10-09
Posts: 32

Re: Finding info about current tasks in /proc

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

#6 2011-12-02 22:27:03

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: Finding info about current tasks in /proc

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

Board footer

Powered by FluxBB