聲明:int getrusage(int who, struct rusage *usage);
getrusage 函數返回當前的資源使用情況。當who 參數為 RUSAGE_SELF 時,返回當前進程的資源使用情況;為 RUSAGE_CHILDREN 時,返回狀態為終止或者等待的子進程使用的資源情況。
返回的結果存在結構體 struct rusage 中:
struct rusage {
struct timeval ru_utime; /* user time used 用戶態使用的時間 */
struct timeval ru_stime; /* system time used 內核態使用的時間 */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
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 */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
用Linux函數printk打印內核信息的方法 http://www.linuxidc.com/Linux/2013-05/83868.htm