Changeset View
Changeset View
Standalone View
Standalone View
bin/ps/ps.c
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | |||||
int cflag; /* -c */ | int cflag; /* -c */ | ||||
int eval; /* Exit value */ | int eval; /* Exit value */ | ||||
time_t now; /* Current time(3) value */ | time_t now; /* Current time(3) value */ | ||||
int rawcpu; /* -C */ | int rawcpu; /* -C */ | ||||
int sumrusage; /* -S */ | int sumrusage; /* -S */ | ||||
int termwidth; /* Width of the screen (0 == infinity). */ | int termwidth; /* Width of the screen (0 == infinity). */ | ||||
int showthreads; /* will threads be shown? */ | int showthreads; /* will threads be shown? */ | ||||
int smp; /* multi-processor support */ | |||||
struct velisthead varlist = STAILQ_HEAD_INITIALIZER(varlist); | struct velisthead varlist = STAILQ_HEAD_INITIALIZER(varlist); | ||||
static int forceuread = DEF_UREAD; /* Do extra work to get u-area. */ | static int forceuread = DEF_UREAD; /* Do extra work to get u-area. */ | ||||
static kvm_t *kd; | static kvm_t *kd; | ||||
static int needcomm; /* -o "command" */ | static int needcomm; /* -o "command" */ | ||||
static int needenv; /* -e */ | static int needenv; /* -e */ | ||||
static int needuser; /* -o "user" */ | static int needuser; /* -o "user" */ | ||||
Show All 36 Lines | |||||
static void free_list(struct listinfo *); | static void free_list(struct listinfo *); | ||||
static void init_list(struct listinfo *, addelem_rtn, int, const char *); | static void init_list(struct listinfo *, addelem_rtn, int, const char *); | ||||
static char *kludge_oldps_options(const char *, char *, const char *); | static char *kludge_oldps_options(const char *, char *, const char *); | ||||
static int pscomp(const void *, const void *); | static int pscomp(const void *, const void *); | ||||
static void saveuser(KINFO *); | static void saveuser(KINFO *); | ||||
static void scanvars(void); | static void scanvars(void); | ||||
static void sizevars(void); | static void sizevars(void); | ||||
static void pidmax_init(void); | static void pidmax_init(void); | ||||
static void smp_init(void); | |||||
static void usage(void); | static void usage(void); | ||||
static char dfmt[] = "pid,tt,state,time,command"; | static char dfmt[] = "pid,tt,state,time,command"; | ||||
static char jfmt[] = "user,pid,ppid,pgid,sid,jobc,state,tt,time,command"; | static char jfmt[] = "user,pid,ppid,pgid,sid,jobc,state,tt,time,command"; | ||||
static char lfmt[] = "uid,pid,ppid,cpu,pri,nice,vsz,rss,mwchan,state," | static char lfmt[] = "uid,pid,ppid,cpu,pri,nice,vsz,rss,mwchan,state," | ||||
"tt,time,command"; | "tt,time,command"; | ||||
static char o1[] = "pid"; | static char o1[] = "pid"; | ||||
static char o2[] = "tt,state,time,command"; | static char o2[] = "tt,state,time,command"; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
/* | /* | ||||
* Hide a number of option-processing kludges in a separate routine, | * Hide a number of option-processing kludges in a separate routine, | ||||
* to support some historical BSD behaviors, such as `ps axu'. | * to support some historical BSD behaviors, such as `ps axu'. | ||||
*/ | */ | ||||
if (argc > 1) | if (argc > 1) | ||||
argv[1] = kludge_oldps_options(PS_ARGS, argv[1], argv[2]); | argv[1] = kludge_oldps_options(PS_ARGS, argv[1], argv[2]); | ||||
pidmax_init(); | pidmax_init(); | ||||
smp_init(); | |||||
all = descendancy = _fmt = nselectors = optfatal = 0; | all = descendancy = _fmt = nselectors = optfatal = 0; | ||||
prtheader = showthreads = wflag = xkeep_implied = 0; | prtheader = showthreads = wflag = xkeep_implied = 0; | ||||
xkeep = -1; /* Neither -x nor -X. */ | xkeep = -1; /* Neither -x nor -X. */ | ||||
init_list(&gidlist, addelem_gid, sizeof(gid_t), "group"); | init_list(&gidlist, addelem_gid, sizeof(gid_t), "group"); | ||||
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"); | ||||
▲ Show 20 Lines • Show All 1,212 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
size_t intsize; | size_t intsize; | ||||
intsize = sizeof(pid_max); | intsize = sizeof(pid_max); | ||||
if (sysctlbyname("kern.pid_max", &pid_max, &intsize, NULL, 0) < 0) { | if (sysctlbyname("kern.pid_max", &pid_max, &intsize, NULL, 0) < 0) { | ||||
xo_warn("unable to read kern.pid_max"); | xo_warn("unable to read kern.pid_max"); | ||||
pid_max = 99999; | pid_max = 99999; | ||||
} | } | ||||
} | |||||
static void | |||||
smp_init(void) | |||||
{ | |||||
size_t size; | |||||
size = sizeof(smp); | |||||
if ((sysctlbyname("machdep.smp_active", &smp, &size, NULL, 0) != 0 && | |||||
sysctlbyname("kern.smp.active", &smp, &size, NULL, 0) != 0) || | |||||
size != sizeof(smp)) | |||||
smp = 0; | |||||
} | } | ||||
static void __dead2 | static void __dead2 | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
#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", | ||||
"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 jid[,jid...]] [-M core] [-N system]", | ||||
" [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]", | " [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]", | ||||
" ps [-L]"); | " ps [-L]"); | ||||
exit(1); | exit(1); | ||||
} | } |