linux手册翻译——getrusage(2)

2021-07-03  本文已影响0人  蟹蟹宁

\color{#A00000}{NAME}
getrusage - get resource usage

\color{#A00000}{SYNOPSIS}

#include <sys/resource.h>
int getrusage(int who, struct rusage *usage);

\color{#A00000}{DESCRIPTION}
getrusage() 用于返回 who 的资源使用量,其中who可以是:

资源使用情况返回在 usage 指向的结构中,其形式如下:

struct rusage {
    struct timeval ru_utime; /* user CPU time used */
    struct timeval ru_stime; /* system CPU 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 (soft page faults) */
    long   ru_majflt;        /* page faults (hard page faults) */
    long   ru_nswap;         /* swaps */
    long   ru_inblock;       /* block input operations */
    long   ru_oublock;       /* block output operations */
    long   ru_msgsnd;        /* IPC messages sent */
    long   ru_msgrcv;        /* IPC messages received */
    long   ru_nsignals;      /* signals received */
    long   ru_nvcsw;         /* voluntary context switches */
    long   ru_nivcsw;        /* involuntary context switches */
};

并非所有字段都已完成; 内核将未维护的字段设置为零。 (提供未维护的字段是为了与其他系统兼容,并且因为有一天它们可能会在 Linux 上得到支持。)这些字段解释如下:

\color{#A00000}{RETURN VALUE}
成功时,返回零。 出错时,返回 -1,并设置 errno 以指示错误。

\color{#A00000}{ERRORS}

\color{#A00000}{ATTRIBUTES}

Interface Attribute Value
getrusage() Thread safety MT-Safe

\color{#A00000}{CONFORMING TO}
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD. POSIX.1 specifies getrusage(), but specifies only the fields ru_utime and ru_stime.
RUSAGE_THREAD is Linux-specific.

\color{#A00000}{NOTES}
资源使用的统计信息,会在execve(2)中保留。

在 2.6.9 之前的 Linux 内核版本中,如果 SIGCHLD 的处置设置为 SIG_IGN,则子进程的资源使用情况会自动包含在 RUSAGE_CHILDREN 返回的值中,尽管 POSIX.1-2001 明确禁止这样做。 这种不符合在 Linux 2.6.9 及更高版本中得到纠正。

本页开头显示的结构定义来自 4.3BSD Reno。

古代系统提供了一个 vtimes() 函数,其目的与 getrusage() 类似。 为了向后兼容,glibc(直到版本 2.32)还提供了 vtimes()。 所有新应用程序都应该使用 getrusage() 编写。 (从 2.33 版开始,glibc 不再提供 vtimes() 实现。)

另请参阅 proc(5) 中 /proc/[pid]/stat 的说明。

上一篇 下一篇

猜你喜欢

热点阅读