Changeset View
Changeset View
Standalone View
Standalone View
bin/ps/ps.c
Context not available. | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <getopt.h> | |||||
#include <grp.h> | #include <grp.h> | ||||
#include <jail.h> | #include <jail.h> | ||||
#include <kvm.h> | #include <kvm.h> | ||||
Context not available. | |||||
"%cpu,%mem,command"; | "%cpu,%mem,command"; | ||||
static char Zfmt[] = "label"; | static char Zfmt[] = "label"; | ||||
#define PS_ARGS "AaCcde" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ" | static struct option longopts[] = { | ||||
{ "jail", required_argument, NULL, 'J' }, | |||||
{ "pid", required_argument, NULL, 'p' }, | |||||
{ "ppid", required_argument, NULL, 'P' }, | |||||
{ "tty", required_argument, NULL, 't' }, | |||||
{ NULL, 0, NULL, 0 } | |||||
}; | |||||
#define PS_ARGS "AaCcde" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:P:rSTt:U:uvwXxZ" | |||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
struct listinfo gidlist, jidlist, pgrplist, pidlist; | struct listinfo gidlist, jidlist, pgrplist, pidlist, ppidlist; | ||||
struct listinfo ruidlist, sesslist, ttylist, uidlist; | struct listinfo ruidlist, sesslist, ttylist, uidlist; | ||||
struct kinfo_proc *kp; | struct kinfo_proc *kp; | ||||
KINFO *kinfo = NULL, *next_KINFO; | KINFO *kinfo = NULL, *next_KINFO; | ||||
Context not available. | |||||
init_list(&jidlist, addelem_jid, sizeof(int), "jail id"); | init_list(&jidlist, addelem_jid, sizeof(int), "jail id"); | ||||
init_list(&pgrplist, addelem_pid, sizeof(pid_t), "process group"); | init_list(&pgrplist, addelem_pid, sizeof(pid_t), "process group"); | ||||
init_list(&pidlist, addelem_pid, sizeof(pid_t), "process id"); | init_list(&pidlist, addelem_pid, sizeof(pid_t), "process id"); | ||||
init_list(&ppidlist, addelem_pid, sizeof(pid_t), "parent process id"); | |||||
init_list(&ruidlist, addelem_uid, sizeof(uid_t), "ruser"); | init_list(&ruidlist, addelem_uid, sizeof(uid_t), "ruser"); | ||||
init_list(&sesslist, addelem_pid, sizeof(pid_t), "session id"); | init_list(&sesslist, addelem_pid, sizeof(pid_t), "session id"); | ||||
init_list(&ttylist, addelem_tty, sizeof(dev_t), "tty"); | init_list(&ttylist, addelem_tty, sizeof(dev_t), "tty"); | ||||
Context not available. | |||||
if (argc < 0) | if (argc < 0) | ||||
exit(1); | exit(1); | ||||
while ((ch = getopt(argc, argv, PS_ARGS)) != -1) | while ((ch = getopt_long(argc, argv, PS_ARGS, longopts, NULL)) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 'A': | case 'A': | ||||
/* | /* | ||||
Context not available. | |||||
*/ | */ | ||||
nselectors++; | nselectors++; | ||||
break; | break; | ||||
case 'P': | |||||
/* | |||||
* Non-standard option corresponding to Linux --ppid. | |||||
*/ | |||||
add_list(&ppidlist, optarg); | |||||
nselectors++; | |||||
break; | |||||
#if 0 | #if 0 | ||||
case 'R': | case 'R': | ||||
/*- | /*- | ||||
Context not available. | |||||
if (kp->ki_pid == pidlist.l.pids[elem]) | if (kp->ki_pid == pidlist.l.pids[elem]) | ||||
goto keepit; | goto keepit; | ||||
} | } | ||||
if (ppidlist.count > 0) { | |||||
for (elem = 0; elem < ppidlist.count; elem++) | |||||
if (kp->ki_ppid == ppidlist.l.pids[elem]) | |||||
goto keepit; | |||||
} | |||||
/* | /* | ||||
* Note that we had to process pidlist before | * Note that we had to process pidlist before | ||||
* filtering out processes which do not have | * filtering out processes which do not have | ||||
Context not available. | |||||
{ | { | ||||
#define SINGLE_OPTS "[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]" | #define SINGLE_OPTS "[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]" | ||||
(void)xo_error("%s\n%s\n%s\n%s\n", | (void)xo_error("%s\n%s\n%s\n%s\n%s\n", | ||||
"usage: ps " SINGLE_OPTS " [-O fmt | -o fmt] [-G gid[,gid...]]", | "usage: ps " SINGLE_OPTS " [-O fmt | -o fmt] [-G gid[,gid...]]", | ||||
" [-J jid[,jid...]] [-M core] [-N system]", | " [-J|--jail jid[,jid...]] [-M core] [-N system]", | ||||
" [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]", | " [-p|--pid pid[,pid...]] [-P|--ppid pid[,pid...]]", | ||||
" [-t tty[,tty...]] [-U user[,user...]]", | |||||
" ps [-L]"); | " ps [-L]"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
Context not available. |