For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2008 > Finding idle process time in unix









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Finding idle process time in unix
Rahul

2008-03-26, 7:43 pm

Hi,

I want to know the idle time (time spent in wait + ready to run
queue) for a process on unix.

One way I thought was to take the start time and end timein a process
(using gettimeofday()) and subtract the cpu time (returned by
clock() ) from their difference, this will fairly be equal to the
total idle time of the process.

Is there any better day using system calls/kernel data structure
which
can be used for the purpose.

Thanks in advance
ppi

2008-03-26, 7:43 pm

> Is there any better day using system calls/kernel data structure
> which
> can be used for the purpose.


Since getrusage() will give you only user time and sys time and not
the real time, you may want to access the proc structure or (yep it's
ugly, you can use our old good friend ps command).

-- paulo
Logan Shaw

2008-03-26, 10:52 pm

Rahul wrote:
> I want to know the idle time (time spent in wait + ready to run
> queue) for a process on unix.
>
> One way I thought was to take the start time and end timein a process
> (using gettimeofday()) and subtract the cpu time (returned by
> clock() ) from their difference, this will fairly be equal to the
> total idle time of the process.
>
> Is there any better day using system calls/kernel data structure
> which
> can be used for the purpose.


As long as we're on that subject, I'm curious if there's a way
(either a portable way, or a way that works on Linux) to find
a related quantity, which could also be called "idle time", but
which is how long it has been since a given process has been
scheduled on a CPU.

As I recall, the "ps" command on SunOS 4.x could give this
information, and a little googling indicates that the "ps"
command on FreeBSD can do it as well (with something like
"ps -v").

It was a really handy thing to have when something strange had
happened recently (like a file was deleted, a packet was sent
or received) and you wanted to see what the likely culprits
were: just sort processes by the time since they last run,
and the culprit either has to be one of those in the right
time frame (or has to have already exited -- and had its exit
status reaped by a wait()er, which could be an accomplice).

- Logan
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com