Getrusage usage in Unix/Linux

Source: Internet
Author: User

# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.