getting %CPU from proc structure

grx0736 at uoft02.utoledo.edu grx0736 at uoft02.utoledo.edu
Sat Jun 1 05:13:09 AEST 1991



	i am writing my own version of remote "ps" to monitor
processes on various Sun machines on a network using RPC. Well,
the problem is not exactly in network programming but in getting
ps -ux style info from the "proc" and "user" structures. Specifically,
how can i get %CPU as output by ps -ux ? 

	proc structure provides two relevant (in my opinion) 
fields:

	proc->p_pctcpu       /* %CPU ? */

	proc->p_cputicks     /* seemingly used in calculating %CPU */

	user structure provides the user and system times, as also
the start time of the process. (i doubt if this is required for %CPU)

	Question: how can i use the above to calculate %CPU ?
		  Or am i off the track in asuming that the above
                  are the only parameters used to calculate %CPU ?

	I do not think proc->p_pctcpu provides direct value to be
	listed as %CPU because the values proc->p_pctcpu bears are
	many a times more than 100.

Any info is highly appreciated.

Sunil



More information about the Comp.unix.questions mailing list