Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message> 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
Post Follow-up to this messageRahul 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.