# Include <sys/resource>
Int getrusage (INT who, struct rusage * r_usage );
Getrusage can be used to obtain information about resources of a process. For example, user overhead time, system overhead Time, and received semaphore;
The following is the structure of the rusage:
Struct rusage {
Struct timeval ru_utime;/* User time used */
Struct timeval ru_stime;/* system time used */
Long ru_maxrss;
# Define ru_first ru_ixrss
Long ru_ixrss;/* XXX: 0 */
Long ru_idrss;/* XXX: Sum of rm_asrss */
Long ru_isrss;/* XXX: 0 */
Long ru_minflt;/* any page faults not requiring I/O */
Long ru_majflt;/* any page faults requiring I/O */
Long ru_nswap;/* swaps */
Long ru_inblock;/* block input operations */
Long ru_oublock;/* block output operations */
Long ru_msgsnd;/* messages sent */
Long ru_msgrcv;/* messages received ed */
Long ru_nsignals;/* signals received */
Long ru_nvcsw;/* Voluntary context switches */
Long ru_nivcsw;/* involuntary "*/
# Define ru_last ru_nivcsw
};
If the parameter "who" is rusage_self, the resource information of the current process is obtained. If it is rusage_childrenThe information about the terminated sub-process and the resources waiting for the sub-process. If the call is successful, 0 is returned; otherwise,-1 is returned;
The following is an example:
Int who = rusage_self;
Struct rusage usage;
Int ret;
Ret = getrusage (WHO, & usage );
In this way, you can use usage to get what you want;
Original post address: http://blog.csdn.net/rojay520/archive/2007/01/22/1489964.aspx