|
NAMEsg_get_process_stats, sg_get_process_stats_r, sg_get_process_count, sg_get_process_count_of, sg_get_process_count_r, sg_free_process_count, sg_process_compare_name, sg_process_compare_pid, sg_process_compare_uid, sg_process_compare_gid, sg_process_compare_size, sg_process_compare_res, sg_process_compare_cpu, sg_process_compare_time - get process statisticsSYNOPSIS#include <statgrab.h>
DESCRIPTIONThe sg_get_process_stats functions provide statistics about the currently running processes. Both functions, sg_get_process_stats() and sg_get_process_stats_r(), take an optional entries parameter, which points (when given) to a size_t to take the number of returned vector entries.The functions sg_get_process_count_of() and sg_get_process_count_r() provide an aggregated view of the process table - they deliver the amount of processes per process state. The sg_get_process_count() is in fact a preprocessor macro for backward compatibility and calls sg_get_process_count_of() with the parameter pcs of sg_entire_process_count to emulate the behavior until 0.17. API Shortcut
The sg_process_stats vectors received from sg_get_process_stats_r() or the sg_process_count summaries received from sg_get_process_count_r must be freed using sg_free_process_stats() or sg_free_process_count(), respectively. The caller is responsible for doing it when the data isn't needed any more. sg_process_compare_name
These functions compare two sg_process_stats entries, and return an int to represent which one is greater. The main use of these functions is to be passed to qsort to sort the sg_process_stats by the given type. Example size_t entries; sg_process_stats *proc_stats = NULL; while( NULL != ( proc_stats = sg_get_process_stats_r(&entries) ) ) { /* order entries by comparing the process identifier */ qsort( proc_stats, entries, sizeof(proc_stats[0]), &sg_process_compare_pid ); show_proc_stats( proc_stats ); sg_free_process_stats( proc_stats ); } RETURN VALUESThe structure returned by sg_get_process_stats is of type sg_process_stats.typedef struct { char *process_name; char *proctitle; pid_t pid; /* process identifier */ pid_t parent; /* Parent pid */ pid_t pgid; /* process id of process group leader */ pid_t sessid; /* session id of the session the process belongs to */ uid_t uid; uid_t euid; gid_t gid; gid_t egid; unsigned long long context_switches; unsigned long long voluntary_context_switches; unsigned long long involuntary_context_switches; unsigned long long proc_size; /* in bytes */ unsigned long long proc_resident; /* in bytes */ time_t start_time; /* When was the process started */ time_t time_spent; /* time running in seconds */ double cpu_percent; int nice; sg_process_state state; time_t systime; } sg_process_stats; typedef enum { SG_PROCESS_STATE_RUNNING, SG_PROCESS_STATE_SLEEPING, SG_PROCESS_STATE_STOPPED, SG_PROCESS_STATE_ZOMBIE, SG_PROCESS_STATE_UNKNOWN } sg_process_state;
The structure returned by sg_get_process_count_of and sg_get_process_count_r is of type sg_process_count. typedef enum sg_process_count_source { sg_entire_process_count, sg_last_process_count } sg_process_count_source; typedef struct{ unsigned long long total; unsigned long long running; unsigned long long sleeping; unsigned long long stopped; unsigned long long zombie; unsigned long long unknown; time_t systime; }sg_process_count;
BUGSThe very first call of sg_get_process_count_of(sg_last_process_count) will return the same as sg_get_process_count_of(sg_entire_process_count).The compare functions exist rather for backward compatibility than for functionality enhancements. Limited flexibility (e.g. reverse order) and lack of optimising opportunities for the compiler leads to the recommendation to implement the required compare routines locally. SEE ALSOstatgrab(3)WEBSITE⟨https://libstatgrab.org/⟩
Visit the GSP FreeBSD Man Page Interface. |