⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reference.texi

📁 linux 操作系统下对系统资源监控程序的编写
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
of @code{glibtop_proclist} are set:@table @code@item numberNumber of entries in the returned list.@item totalTotal size of the returned list (this equals @code{number * size}).@item sizeSize of a single entry in the returned list(this equals @code{sizeof (unsigned)}).@end tableThe returned list is allocated using @code{g_malloc} and must be freedusing @code{g_free} to avoid a memory leak.@page@node glibtop_proc_state, glibtop_proc_uid, glibtop_proclist, System Dependent@subsection Process StateLibrary function @code{glibtop_get_proc_state}:@example@cartouchevoidglibtop_get_proc_state (glibtop_proc_state *buf, pid_t pid);voidglibtop_get_proc_state_l (glibtop *server, glibtop_proc_state *buf,                          pid_t pid);@end cartouche@end exampleDeclaration of @code{glibtop_proc_state} in @file{<glibtop/proc_state.h>}:@example@cartouchetypedef struct _glibtop_proc_state      glibtop_proc_state;struct _glibtop_proc_state@{    guint64 flags;    char cmd[40];@ifset LIBGTOP-1-1    unsigned state;@end ifset@ifclear LIBGTOP-1-1    char state;@end ifclear    int uid,        gid,        ruid,        rgid;    int has_cpu,        processor,        last_processor;@};@end cartouche@end example@table @code@item cmdBasename of the executable file in the call to @code{exec}.@item state@ifset LIBGTOP-1-1Process state (see the constants defined below).@end ifset@ifclear LIBGTOP-1-1Process state ('R' = running, 'S' = sleeping, 'D' = uninterruptible,'Z' = zombie, 'T' = stopped, 'I' = idle).This was changed to an @code{unsigned} bitfield in LibGTop 1.1.x where thereare also some constants for it.@end ifclear@end tableWhen porting LibGTop, please @emph{try hard} to implement the followingfields. For security reasons, it is @strong{very important} that you@strong{only} set the @code{flags} bits for those fields if their@strong{values are correct}.@table @code@item uidEffective UID of the process.@item gidEffective GID of the process.@item ruidReal UID of the process.@item rgidRead GID of the process.@end tableThe following fields are for SMP systems:@table @code@item has_cpuThis is either 0 or 1 depending on whether the process currently has a CPUor not.@item processorThis is the processor id of the CPU this process is currently running on(which can be used as index in the @samp{xcpu_} fields of @code{glibtop_cpu}for instance; since zero is a valid processor id, you must check @code{has_cpu}in this case to find out whether the process really has a CPU).@item last_processorThe is the processor id of the CPU the process was last running on.@end table@ifset LIBGTOP-1-1There are some constants for the @code{state} field:@example@cartouche#define GLIBTOP_PROCESS_RUNNING                 1#define GLIBTOP_PROCESS_INTERRUPTIBLE           2#define GLIBTOP_PROCESS_UNINTERRUPTIBLE         4#define GLIBTOP_PROCESS_ZOMBIE                  8#define GLIBTOP_PROCESS_STOPPED                 16#define GLIBTOP_PROCESS_SWAPPING                32@end cartouche@end example@end ifset@table @code@item GLIBTOP_PROCESS_RUNNINGThe process is currently running.@item GLIBTOP_PROCESS_INTERRUPTIBLEThe process is currently in an interruptible sleep.@item GLIBTOP_PROCESS_UNINTERRUPTIBLEThe process is currently in uninterruptible sleep(the so-called @dfn{disk sleep}).@item GLIBTOP_PROCESS_ZOMBIEThe process is a zombie.@item GLIBTOP_PROCESS_STOPPEDThe process is currently stopped (received @code{SIGSTOP}or attached to a debugger).@item GLIBTOP_PROCESS_SWAPPINGThe process is currently swapping.@end table@page@node glibtop_proc_uid, glibtop_proc_mem, glibtop_proc_state, System Dependent@subsection Process UID and TTY informationLibrary function @code{glibtop_get_proc_uid}:@example@cartouchevoidglibtop_get_proc_uid (glibtop_proc_uid *buf, pid_t pid);voidglibtop_get_proc_uid_l (glibtop *server, glibtop_proc_uid *buf,                        pid_t pid);@end cartouche@end exampleDeclaration of @code{glibtop_proc_uid} in @file{<glibtop/procuid.h>}:@example@cartouchetypedef struct _glibtop_proc_uid        glibtop_proc_uid;struct _glibtop_proc_uid@{    guint64 flags;    int uid,        euid,        gid,        egid,        suid,        sgid,        fsuid,        fsgid,        pid,        ppid,        pgrp,        session,        tty,        tpgid,        priority,        nice,        ngroups,        groups [GLIBTOP_MAX_GROUPS];@};@end cartouche@end example@table @code@item uidUser ID@item euidEffective User ID@item gidGroup ID@item egidEffective Group ID@item pidProcess ID@item ppidPID of parent process@item pgrpProcess group ID@item sessionSession ID@item ttyFull device number of controlling terminal@item tpgidTerminal process group ID@item priorityKernel scheduling priority.@item niceStandard unix nice level of process.@item ngroupsNumber of additional process groups.@item groupsArray of additional process groups@*(@code{GLIBTOP_MAX_GROUPS} is defined in @file{<glibtop/limits.h>}).@end table@page@node glibtop_proc_mem, glibtop_proc_time, glibtop_proc_uid, System Dependent@subsection Process Memory informationLibrary function @code{glibtop_get_proc_mem}:@example@cartouchevoidglibtop_get_proc_mem (glibtop_proc_mem *buf, pid_t pid);voidglibtop_get_proc_mem_l (glibtop *server, glibtop_proc_mem *buf,                        pid_t pid);@end cartouche@end exampleDeclaration of @code{glibtop_proc_mem} in @file{<glibtop/procmem.h>}:@example@cartouchetypedef struct _glibtop_proc_mem        glibtop_proc_mem;struct _glibtop_proc_mem@{    guint64   flags,        size,        vsize,        resident,        share,        rss,        rss_rlim;@};@end cartouche@end example@table @code@item sizeTotal number of pages of memory.@item vsizeNumber of pages of virtual memory.@item residentNumber of residnet set (non-swapped) pages.@item shareNumber of pages of shared (mmap'd) memory.@item rssNumber of pages the process has in real memory, minus 3 for administrativepurposes.This is just the pages which count towards text, data, or stack space.This does not include pages which have not been demand-loaded in, or whichare swapped out.@item rss_rlimCurrent limit in bytes on the rss of the process (usually 2,147,483,647).@end tableThe description above is taken from the manual page of the @file{/proc}filesystem under Linux and is a little bit confusing, so I make this clearhere. @strong{Note for people porting LibGTop to other systems:}Every operating system has its own idea about the memory usage of a processand also system utilities like @code{ps} show different things on differentsystems.Nevertheless, we should try to make LibGTop as system independent as possible,so I give you some hints here how @code{glibtop_get_proc_mem} should work. @itemize @bullet@itemWhen you use @code{mmap} with either @code{MAP_SHARED} or @code{MAP_PRIVATE},this should only affect the @code{vsize} of the process and none of its@code{size}, @code{resident}, @code{shared} and @code{rss} sizes.@itemAs soon as you read some of the @code{mmap()}ed pages, they will be demand-oaded and thus count towards the @code{size} of the process.Also - we assume there is enough free memory - they are resident in memoryuntil they get stolen or swapped out and thus increase the @code{resident} and@code{rss} sizes of the process.@itemIf the process has used @code{MAP_SHARED} and another process attaches thesame file also @code{MAP_SHARED}, some of the pages are shared with thisprocess and thus increase the @code{shared} sizes of both processes.@itemIf the process has used @code{MAP_PRIVATE} and writes to the @code{mmap()}edpages, the only difference to reading from them is that they get dirty andcannot be stolen any longer but will get swapped out.@itemWhen memory gets rare, clean pages are normally stolen, which decreases the@code{size}, @code{resident}, @code{shared} and @code{rss} sizes of the process.@itemWhen dirty pages are swapped out, this will not decrease the @code{size} of theprocess but only its @code{resident} and @code{rss} sizes (dirty pages cannotbe shared).@itemThe @code{vsize} of a process can @emph{only} be changed by the processitself when it requests or frees memory but @emph{never} due to swappingactivity of the system.@itemIf the @code{shared} size changes, this @emph{only} means that the number ofpages that are currently shared with other processes has changed; if thishappens, this will @emph{never} affect any of the other sizes of the process.@end itemizeThe hints above describe how it works under Linux - but we should try to make@code{glibtop_get_proc_mem} show the same behavior under every other system.@page@node glibtop_proc_time, glibtop_proc_signal, glibtop_proc_mem, System Dependent@subsection Process Time informationLibrary function @code{glibtop_get_proc_time}:@example@cartouchevoidglibtop_get_proc_time (glibtop_proc_time *buf, pid_t pid);voidglibtop_get_proc_time_l (glibtop *server, glibtop_proc_time *buf,                         pid_t pid);@end cartouche@end exampleDeclaration of @code{glibtop_proc_time} in @file{<glibtop/proctime.h>}:@example@cartouchetypedef struct _glibtop_proc_time       glibtop_proc_time;struct _glibtop_proc_time@{    guint64   flags,        start_time,        rtime,        utime,        stime,        cutime,        cstime,        timeout,        it_real_value,        frequency,        xcpu_utime [GLIBTOP_NCPU],        xcpu_stime [GLIBTOP_NCPU],        xcpu_flags;@};@end cartouche@end example@table @code@item start_timeStart time of process in seconds since the epoch@item rtimeReal time accumulated by process (should be @code{utime} + @code{stime})@item utimeUser-mode CPU time accumulated by process@item stimeKernel-mode CPU time accumulated by process@item cutimeCumulative utime of process and reaped children@item cstimeCumulative stime of process and reaped children@item timeoutThe time (in jiffies) of the process's next timeout@item it_real_valueThe time (in jiffies) before the next SIGALRM is sent to the process dueto an interval timer.@item frequencyTick frequency@item xcpu_utimeSMP user-mode CPU time accumulated by process@item xcpu_stimeSMP kernel-mode CPU time accumulated by process@end table@page@node glibtop_proc_signal, glibtop_proc_kernel, glibtop_proc_time, System Dependent@subsection Process Signal informationLibrary function @code{glibtop_get_proc_signal}:@example@cartouchevoidglibtop_get_proc_signal (glibtop_proc_signal *buf, pid_t pid);voidglibtop_get_proc_signal_l (glibtop *server, glibtop_proc_signal *buf,                           pid_t pid);@end cartouche@end exampleDeclaration of @code{glibtop_proc_signal} in @file{<glibtop/procsignal.h>}:@example@cartouchetypedef struct _glibtop_proc_signal     glibtop_proc_signal;struct _glibtop_proc_signal@{    guint64   flags,        signal [2],        blocked [2],        sigignore [2],        sigcatch [2];@};@end cartouche@end example@table @code@item signalMask of pending signals@item blockedMask of blocked signals@item sigignoreMask of ignored signals@item sigcatchMask of caught signals@end tableAll signal masks are interpreted as bit mask; it is an array of two

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -