proc.h (3055B)
1 /* see LICENSE file for copyright and license details */ 2 #ifndef ARUU_PROC_H 3 #define ARUU_PROC_H 4 5 #include <sys/types.h> 6 7 #include <limits.h> 8 #include <stddef.h> 9 #include <time.h> 10 11 struct procstat { 12 int pid; 13 char comm[PATH_MAX + 2]; /* + 2 for '(' and ')' */ 14 unsigned char state; 15 int ppid; 16 int pgrp; 17 int sid; 18 int tty_nr; 19 int tpgid; 20 unsigned flags; 21 unsigned long minflt; 22 unsigned long cminflt; 23 unsigned long majflt; 24 unsigned long cmajflt; 25 unsigned long utime; 26 unsigned long stime; 27 long cutime; 28 long cstime; 29 long priority; 30 long nice; 31 long num_threads; 32 long itrealvalue; 33 unsigned long long starttime; 34 unsigned long vsize; 35 long rss; 36 unsigned long rsslim; 37 }; 38 39 struct procstatus { 40 uid_t uid; 41 uid_t euid; 42 gid_t gid; 43 gid_t egid; 44 }; 45 46 int parsecmdline(pid_t pid, char *buf, size_t siz); 47 int parsestat(pid_t pid, struct procstat *ps); 48 int parsestatus(pid_t pid, struct procstatus *pstatus); 49 int proceuid(pid_t pid, uid_t *euid); 50 int procuid(pid_t pid, uid_t *euid); 51 int pidfile(const char *file); 52 53 /* the process table, as every kernel's tools want it: one row per process in 54 * words that are not any kernel's. proc_linux.c reads it from /proc, and 55 * proc_posix.c says a kernel has no backend yet, so ps, pgrep and pkill 56 * are the same code everywhere and a port is one file */ 57 struct procinfo { 58 pid_t pid, ppid, pgid, sid; 59 uid_t ruid, euid; 60 gid_t rgid, egid; 61 unsigned tty_major, tty_minor; /* 0 0 for no terminal */ 62 char state; /* R S D Z T, as ps prints it */ 63 long nice, priority; 64 long nthreads; 65 time_t start; /* when it began, seconds since the epoch */ 66 unsigned long cpu; /* seconds of cpu time, system and user */ 67 unsigned long vsize_kib; 68 long rss_kib; 69 char comm[256]; 70 }; 71 72 typedef int proc_fn(const struct procinfo *p, void *arg); 73 74 /* fn for every process there is, until it returns non zero. -1 with errno 75 * set when the table cannot be read, ENOTSUP where there is no backend */ 76 int proc_each(proc_fn *fn, void *arg); 77 int proc_info(pid_t pid, struct procinfo *p); 78 /* the command line, its words joined by spaces. -1 for a process with none, 79 * a kernel thread or a zombie */ 80 int proc_args(pid_t pid, char *buf, size_t n); 81 /* the working directory of a process, -1 when it cannot be told: it is gone, 82 * it is another user's, or the kernel keeps no such thing */ 83 int proc_cwd(pid_t pid, char *buf, size_t n); 84 /* the terminal's name as ps shows it: pts/3, tty1 or ? for none */ 85 void proc_ttyname(unsigned major, unsigned minor, char *buf, size_t n); 86 /* the path of the running program's own file, readlink style: not 87 * terminated, -1 where the kernel does not tell */ 88 ssize_t proc_selfexe(char *buf, size_t n); 89 90 #endif