ps.c revision 1.21 1 1.21 mrg /* $NetBSD: ps.c,v 1.21 1998/07/06 07:50:18 mrg Exp $ */
2 1.13 cgd
3 1.1 cgd /*-
4 1.11 cgd * Copyright (c) 1990, 1993, 1994
5 1.11 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.19 christos #include <sys/cdefs.h>
37 1.1 cgd #ifndef lint
38 1.19 christos __COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\
39 1.19 christos The Regents of the University of California. All rights reserved.\n");
40 1.1 cgd #endif /* not lint */
41 1.1 cgd
42 1.1 cgd #ifndef lint
43 1.13 cgd #if 0
44 1.11 cgd static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94";
45 1.13 cgd #else
46 1.21 mrg __RCSID("$NetBSD: ps.c,v 1.21 1998/07/06 07:50:18 mrg Exp $");
47 1.13 cgd #endif
48 1.1 cgd #endif /* not lint */
49 1.1 cgd
50 1.1 cgd #include <sys/param.h>
51 1.1 cgd #include <sys/user.h>
52 1.1 cgd #include <sys/time.h>
53 1.1 cgd #include <sys/resource.h>
54 1.1 cgd #include <sys/proc.h>
55 1.1 cgd #include <sys/stat.h>
56 1.1 cgd #include <sys/ioctl.h>
57 1.11 cgd #include <sys/sysctl.h>
58 1.11 cgd
59 1.11 cgd #include <ctype.h>
60 1.11 cgd #include <err.h>
61 1.11 cgd #include <errno.h>
62 1.11 cgd #include <fcntl.h>
63 1.11 cgd #include <kvm.h>
64 1.17 pk #include <limits.h>
65 1.1 cgd #include <nlist.h>
66 1.11 cgd #include <paths.h>
67 1.1 cgd #include <stdio.h>
68 1.1 cgd #include <stdlib.h>
69 1.1 cgd #include <string.h>
70 1.11 cgd #include <unistd.h>
71 1.11 cgd
72 1.1 cgd #include "ps.h"
73 1.1 cgd
74 1.10 cgd #ifdef P_PPWAIT
75 1.1 cgd #define NEWVM
76 1.1 cgd #endif
77 1.1 cgd
78 1.1 cgd KINFO *kinfo;
79 1.1 cgd struct varent *vhead, *vtail;
80 1.1 cgd
81 1.1 cgd int eval; /* exit value */
82 1.1 cgd int rawcpu; /* -C */
83 1.1 cgd int sumrusage; /* -S */
84 1.1 cgd int termwidth; /* width of screen (0 == infinity) */
85 1.1 cgd int totwidth; /* calculated width of requested variables */
86 1.1 cgd
87 1.15 mycroft int needuser, needcomm, needenv, commandonly;
88 1.1 cgd
89 1.1 cgd enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
90 1.1 cgd
91 1.11 cgd static char *kludge_oldps_options __P((char *));
92 1.11 cgd static int pscomp __P((const void *, const void *));
93 1.11 cgd static void saveuser __P((KINFO *));
94 1.11 cgd static void scanvars __P((void));
95 1.11 cgd static void usage __P((void));
96 1.19 christos int main __P((int, char *[]));
97 1.1 cgd
98 1.1 cgd char dfmt[] = "pid tt state time command";
99 1.1 cgd char jfmt[] = "user pid ppid pgid sess jobc state tt time command";
100 1.1 cgd char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command";
101 1.1 cgd char o1[] = "pid";
102 1.1 cgd char o2[] = "tt state time command";
103 1.1 cgd char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command";
104 1.11 cgd char vfmt[] = "pid state time sl re pagein vsz rss lim tsiz %cpu %mem command";
105 1.11 cgd
106 1.11 cgd kvm_t *kd;
107 1.1 cgd
108 1.11 cgd int
109 1.1 cgd main(argc, argv)
110 1.1 cgd int argc;
111 1.11 cgd char *argv[];
112 1.1 cgd {
113 1.11 cgd struct kinfo_proc *kp;
114 1.11 cgd struct varent *vent;
115 1.1 cgd struct winsize ws;
116 1.1 cgd dev_t ttydev;
117 1.11 cgd pid_t pid;
118 1.11 cgd uid_t uid;
119 1.21 mrg gid_t egid = getegid();
120 1.15 mycroft int all, ch, flag, i, fmt, lineno, nentries;
121 1.11 cgd int prtheader, wflag, what, xflg;
122 1.17 pk char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX];
123 1.1 cgd
124 1.21 mrg (void)setegid(getgid());
125 1.1 cgd if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
126 1.1 cgd ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
127 1.1 cgd ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&ws) == -1) ||
128 1.1 cgd ws.ws_col == 0)
129 1.1 cgd termwidth = 79;
130 1.1 cgd else
131 1.1 cgd termwidth = ws.ws_col - 1;
132 1.1 cgd
133 1.1 cgd if (argc > 1)
134 1.1 cgd argv[1] = kludge_oldps_options(argv[1]);
135 1.1 cgd
136 1.15 mycroft all = fmt = prtheader = wflag = xflg = 0;
137 1.11 cgd pid = -1;
138 1.11 cgd uid = (uid_t) -1;
139 1.1 cgd ttydev = NODEV;
140 1.1 cgd memf = nlistf = swapf = NULL;
141 1.1 cgd while ((ch = getopt(argc, argv,
142 1.20 lukem "acCeghjLlM:mN:O:o:p:rSTt:uvW:wx")) != -1)
143 1.1 cgd switch((char)ch) {
144 1.1 cgd case 'a':
145 1.1 cgd all = 1;
146 1.1 cgd break;
147 1.12 mycroft case 'c':
148 1.12 mycroft commandonly = 1;
149 1.12 mycroft break;
150 1.11 cgd case 'e': /* XXX set ufmt */
151 1.11 cgd needenv = 1;
152 1.11 cgd break;
153 1.1 cgd case 'C':
154 1.1 cgd rawcpu = 1;
155 1.1 cgd break;
156 1.1 cgd case 'g':
157 1.11 cgd break; /* no-op */
158 1.1 cgd case 'h':
159 1.1 cgd prtheader = ws.ws_row > 5 ? ws.ws_row : 22;
160 1.1 cgd break;
161 1.1 cgd case 'j':
162 1.1 cgd parsefmt(jfmt);
163 1.15 mycroft fmt = 1;
164 1.1 cgd jfmt[0] = '\0';
165 1.1 cgd break;
166 1.11 cgd case 'L':
167 1.1 cgd showkey();
168 1.1 cgd exit(0);
169 1.1 cgd case 'l':
170 1.1 cgd parsefmt(lfmt);
171 1.15 mycroft fmt = 1;
172 1.1 cgd lfmt[0] = '\0';
173 1.1 cgd break;
174 1.1 cgd case 'M':
175 1.1 cgd memf = optarg;
176 1.1 cgd break;
177 1.1 cgd case 'm':
178 1.1 cgd sortby = SORTMEM;
179 1.1 cgd break;
180 1.1 cgd case 'N':
181 1.1 cgd nlistf = optarg;
182 1.1 cgd break;
183 1.1 cgd case 'O':
184 1.1 cgd parsefmt(o1);
185 1.1 cgd parsefmt(optarg);
186 1.1 cgd parsefmt(o2);
187 1.1 cgd o1[0] = o2[0] = '\0';
188 1.15 mycroft fmt = 1;
189 1.1 cgd break;
190 1.1 cgd case 'o':
191 1.1 cgd parsefmt(optarg);
192 1.15 mycroft fmt = 1;
193 1.1 cgd break;
194 1.1 cgd case 'p':
195 1.11 cgd pid = atol(optarg);
196 1.1 cgd xflg = 1;
197 1.1 cgd break;
198 1.1 cgd case 'r':
199 1.1 cgd sortby = SORTCPU;
200 1.1 cgd break;
201 1.1 cgd case 'S':
202 1.1 cgd sumrusage = 1;
203 1.1 cgd break;
204 1.1 cgd case 'T':
205 1.1 cgd if ((optarg = ttyname(STDIN_FILENO)) == NULL)
206 1.11 cgd errx(1, "stdin: not a terminal");
207 1.1 cgd /* FALLTHROUGH */
208 1.1 cgd case 't': {
209 1.11 cgd struct stat sb;
210 1.11 cgd char *ttypath, pathbuf[MAXPATHLEN];
211 1.1 cgd
212 1.1 cgd if (strcmp(optarg, "co") == 0)
213 1.1 cgd ttypath = _PATH_CONSOLE;
214 1.1 cgd else if (*optarg != '/')
215 1.11 cgd (void)snprintf(ttypath = pathbuf,
216 1.11 cgd sizeof(pathbuf), "%s%s", _PATH_TTY, optarg);
217 1.1 cgd else
218 1.1 cgd ttypath = optarg;
219 1.11 cgd if (stat(ttypath, &sb) == -1)
220 1.11 cgd err(1, "%s", ttypath);
221 1.11 cgd if (!S_ISCHR(sb.st_mode))
222 1.11 cgd errx(1, "%s: not a terminal", ttypath);
223 1.11 cgd ttydev = sb.st_rdev;
224 1.1 cgd break;
225 1.1 cgd }
226 1.1 cgd case 'u':
227 1.1 cgd parsefmt(ufmt);
228 1.1 cgd sortby = SORTCPU;
229 1.15 mycroft fmt = 1;
230 1.1 cgd ufmt[0] = '\0';
231 1.1 cgd break;
232 1.1 cgd case 'v':
233 1.1 cgd parsefmt(vfmt);
234 1.1 cgd sortby = SORTMEM;
235 1.15 mycroft fmt = 1;
236 1.1 cgd vfmt[0] = '\0';
237 1.1 cgd break;
238 1.1 cgd case 'W':
239 1.1 cgd swapf = optarg;
240 1.1 cgd break;
241 1.1 cgd case 'w':
242 1.6 cgd if (wflag)
243 1.6 cgd termwidth = UNLIMITED;
244 1.6 cgd else if (termwidth < 131)
245 1.1 cgd termwidth = 131;
246 1.11 cgd wflag++;
247 1.1 cgd break;
248 1.1 cgd case 'x':
249 1.1 cgd xflg = 1;
250 1.1 cgd break;
251 1.1 cgd case '?':
252 1.1 cgd default:
253 1.1 cgd usage();
254 1.1 cgd }
255 1.1 cgd argc -= optind;
256 1.1 cgd argv += optind;
257 1.1 cgd
258 1.1 cgd #define BACKWARD_COMPATIBILITY
259 1.1 cgd #ifdef BACKWARD_COMPATIBILITY
260 1.1 cgd if (*argv) {
261 1.1 cgd nlistf = *argv;
262 1.1 cgd if (*++argv) {
263 1.1 cgd memf = *argv;
264 1.1 cgd if (*++argv)
265 1.1 cgd swapf = *argv;
266 1.1 cgd }
267 1.1 cgd }
268 1.1 cgd #endif
269 1.11 cgd /*
270 1.21 mrg * Discard setgid privileges. If not the running kernel, we toss
271 1.21 mrg * them away totally so that bad guys can't print interesting stuff
272 1.21 mrg * from kernel memory, otherwise switch back to kmem for the
273 1.21 mrg * duration of the kvm_openfiles() call.
274 1.11 cgd */
275 1.11 cgd if (nlistf != NULL || memf != NULL || swapf != NULL)
276 1.21 mrg (void)setgid(getgid());
277 1.21 mrg else
278 1.21 mrg (void)setegid(egid);
279 1.11 cgd
280 1.11 cgd kd = kvm_openfiles(nlistf, memf, swapf, O_RDONLY, errbuf);
281 1.11 cgd if (kd == 0)
282 1.11 cgd errx(1, "%s", errbuf);
283 1.21 mrg
284 1.21 mrg if (nlistf == NULL && memf == NULL && swapf == NULL)
285 1.21 mrg (void)setgid(getgid());
286 1.1 cgd
287 1.15 mycroft if (!fmt)
288 1.1 cgd parsefmt(dfmt);
289 1.1 cgd
290 1.1 cgd if (!all && ttydev == NODEV && pid == -1) /* XXX - should be cleaner */
291 1.1 cgd uid = getuid();
292 1.1 cgd
293 1.1 cgd /*
294 1.1 cgd * scan requested variables, noting what structures are needed,
295 1.1 cgd * and adjusting header widths as appropiate.
296 1.1 cgd */
297 1.1 cgd scanvars();
298 1.1 cgd /*
299 1.1 cgd * get proc list
300 1.1 cgd */
301 1.11 cgd if (uid != (uid_t) -1) {
302 1.11 cgd what = KERN_PROC_UID;
303 1.1 cgd flag = uid;
304 1.1 cgd } else if (ttydev != NODEV) {
305 1.11 cgd what = KERN_PROC_TTY;
306 1.1 cgd flag = ttydev;
307 1.1 cgd } else if (pid != -1) {
308 1.11 cgd what = KERN_PROC_PID;
309 1.1 cgd flag = pid;
310 1.11 cgd } else {
311 1.11 cgd what = KERN_PROC_ALL;
312 1.11 cgd flag = 0;
313 1.11 cgd }
314 1.1 cgd /*
315 1.1 cgd * select procs
316 1.1 cgd */
317 1.11 cgd if ((kp = kvm_getprocs(kd, what, flag, &nentries)) == 0)
318 1.11 cgd errx(1, "%s", kvm_geterr(kd));
319 1.11 cgd if ((kinfo = malloc(nentries * sizeof(*kinfo))) == NULL)
320 1.19 christos err(1, "%s", "");
321 1.11 cgd for (i = nentries; --i >= 0; ++kp) {
322 1.11 cgd kinfo[i].ki_p = kp;
323 1.11 cgd if (needuser)
324 1.11 cgd saveuser(&kinfo[i]);
325 1.1 cgd }
326 1.1 cgd /*
327 1.1 cgd * print header
328 1.1 cgd */
329 1.1 cgd printheader();
330 1.1 cgd if (nentries == 0)
331 1.1 cgd exit(0);
332 1.1 cgd /*
333 1.1 cgd * sort proc list
334 1.1 cgd */
335 1.11 cgd qsort(kinfo, nentries, sizeof(KINFO), pscomp);
336 1.1 cgd /*
337 1.1 cgd * for each proc, call each variable output function.
338 1.1 cgd */
339 1.1 cgd for (i = lineno = 0; i < nentries; i++) {
340 1.14 mycroft KINFO *ki = &kinfo[i];
341 1.14 mycroft
342 1.14 mycroft if (xflg == 0 && (KI_EPROC(ki)->e_tdev == NODEV ||
343 1.14 mycroft (KI_PROC(ki)->p_flag & P_CONTROLT ) == 0))
344 1.1 cgd continue;
345 1.1 cgd for (vent = vhead; vent; vent = vent->next) {
346 1.14 mycroft (vent->var->oproc)(ki, vent);
347 1.1 cgd if (vent->next != NULL)
348 1.11 cgd (void)putchar(' ');
349 1.1 cgd }
350 1.11 cgd (void)putchar('\n');
351 1.11 cgd if (prtheader && lineno++ == prtheader - 4) {
352 1.11 cgd (void)putchar('\n');
353 1.1 cgd printheader();
354 1.1 cgd lineno = 0;
355 1.1 cgd }
356 1.1 cgd }
357 1.1 cgd exit(eval);
358 1.1 cgd }
359 1.1 cgd
360 1.11 cgd static void
361 1.1 cgd scanvars()
362 1.1 cgd {
363 1.11 cgd struct varent *vent;
364 1.11 cgd VAR *v;
365 1.11 cgd int i;
366 1.1 cgd
367 1.1 cgd for (vent = vhead; vent; vent = vent->next) {
368 1.1 cgd v = vent->var;
369 1.1 cgd i = strlen(v->header);
370 1.1 cgd if (v->width < i)
371 1.1 cgd v->width = i;
372 1.1 cgd totwidth += v->width + 1; /* +1 for space */
373 1.1 cgd if (v->flag & USER)
374 1.1 cgd needuser = 1;
375 1.1 cgd if (v->flag & COMM)
376 1.1 cgd needcomm = 1;
377 1.1 cgd }
378 1.1 cgd totwidth--;
379 1.11 cgd }
380 1.1 cgd
381 1.11 cgd static void
382 1.1 cgd saveuser(ki)
383 1.1 cgd KINFO *ki;
384 1.1 cgd {
385 1.11 cgd struct pstats pstats;
386 1.11 cgd struct usave *usp;
387 1.5 cgd
388 1.11 cgd usp = &ki->ki_u;
389 1.11 cgd if (kvm_read(kd, (u_long)&KI_PROC(ki)->p_addr->u_stats,
390 1.11 cgd (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) {
391 1.1 cgd /*
392 1.11 cgd * The u-area might be swapped out, and we can't get
393 1.11 cgd * at it because we have a crashdump and no swap.
394 1.11 cgd * If it's here fill in these fields, otherwise, just
395 1.11 cgd * leave them 0.
396 1.1 cgd */
397 1.11 cgd usp->u_start = pstats.p_start;
398 1.11 cgd usp->u_ru = pstats.p_ru;
399 1.11 cgd usp->u_cru = pstats.p_cru;
400 1.11 cgd usp->u_valid = 1;
401 1.1 cgd } else
402 1.11 cgd usp->u_valid = 0;
403 1.1 cgd }
404 1.1 cgd
405 1.11 cgd static int
406 1.11 cgd pscomp(a, b)
407 1.11 cgd const void *a, *b;
408 1.1 cgd {
409 1.1 cgd int i;
410 1.1 cgd #ifdef NEWVM
411 1.11 cgd #define VSIZE(k) (KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize + \
412 1.11 cgd KI_EPROC(k)->e_vm.vm_tsize)
413 1.1 cgd #else
414 1.1 cgd #define VSIZE(k) ((k)->ki_p->p_dsize + (k)->ki_p->p_ssize + (k)->ki_e->e_xsize)
415 1.1 cgd #endif
416 1.1 cgd
417 1.1 cgd if (sortby == SORTCPU)
418 1.11 cgd return (getpcpu((KINFO *)b) - getpcpu((KINFO *)a));
419 1.1 cgd if (sortby == SORTMEM)
420 1.11 cgd return (VSIZE((KINFO *)b) - VSIZE((KINFO *)a));
421 1.11 cgd i = KI_EPROC((KINFO *)a)->e_tdev - KI_EPROC((KINFO *)b)->e_tdev;
422 1.1 cgd if (i == 0)
423 1.11 cgd i = KI_PROC((KINFO *)a)->p_pid - KI_PROC((KINFO *)b)->p_pid;
424 1.1 cgd return (i);
425 1.1 cgd }
426 1.1 cgd
427 1.1 cgd /*
428 1.1 cgd * ICK (all for getopt), would rather hide the ugliness
429 1.1 cgd * here than taint the main code.
430 1.1 cgd *
431 1.1 cgd * ps foo -> ps -foo
432 1.1 cgd * ps 34 -> ps -p34
433 1.1 cgd *
434 1.1 cgd * The old convention that 't' with no trailing tty arg means the users
435 1.1 cgd * tty, is only supported if argv[1] doesn't begin with a '-'. This same
436 1.1 cgd * feature is available with the option 'T', which takes no argument.
437 1.1 cgd */
438 1.11 cgd static char *
439 1.1 cgd kludge_oldps_options(s)
440 1.1 cgd char *s;
441 1.1 cgd {
442 1.1 cgd size_t len;
443 1.1 cgd char *newopts, *ns, *cp;
444 1.1 cgd
445 1.1 cgd len = strlen(s);
446 1.16 thorpej if ((newopts = ns = malloc(len + 3)) == NULL)
447 1.19 christos err(1, "%s", "");
448 1.1 cgd /*
449 1.1 cgd * options begin with '-'
450 1.1 cgd */
451 1.1 cgd if (*s != '-')
452 1.1 cgd *ns++ = '-'; /* add option flag */
453 1.1 cgd /*
454 1.1 cgd * gaze to end of argv[1]
455 1.1 cgd */
456 1.1 cgd cp = s + len - 1;
457 1.1 cgd /*
458 1.1 cgd * if last letter is a 't' flag with no argument (in the context
459 1.1 cgd * of the oldps options -- option string NOT starting with a '-' --
460 1.1 cgd * then convert to 'T' (meaning *this* terminal, i.e. ttyname(0)).
461 1.1 cgd */
462 1.1 cgd if (*cp == 't' && *s != '-')
463 1.1 cgd *cp = 'T';
464 1.1 cgd else {
465 1.1 cgd /*
466 1.1 cgd * otherwise check for trailing number, which *may* be a
467 1.1 cgd * pid.
468 1.1 cgd */
469 1.1 cgd while (cp >= s && isdigit(*cp))
470 1.1 cgd --cp;
471 1.1 cgd }
472 1.1 cgd cp++;
473 1.11 cgd memmove(ns, s, (size_t)(cp - s)); /* copy up to trailing number */
474 1.1 cgd ns += cp - s;
475 1.1 cgd /*
476 1.1 cgd * if there's a trailing number, and not a preceding 'p' (pid) or
477 1.1 cgd * 't' (tty) flag, then assume it's a pid and insert a 'p' flag.
478 1.1 cgd */
479 1.19 christos if (isdigit(*cp) && (cp == s || (cp[-1] != 't' && cp[-1] != 'p' &&
480 1.19 christos (cp - 1 == s || cp[-2] != 't'))))
481 1.1 cgd *ns++ = 'p';
482 1.18 mrg /* and append the number */
483 1.18 mrg (void)strcpy(ns, cp); /* XXX strcpy is safe */
484 1.1 cgd
485 1.1 cgd return (newopts);
486 1.1 cgd }
487 1.1 cgd
488 1.11 cgd static void
489 1.11 cgd usage()
490 1.1 cgd {
491 1.1 cgd
492 1.11 cgd (void)fprintf(stderr,
493 1.11 cgd "usage:\t%s\n\t %s\n\t%s\n",
494 1.11 cgd "ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty]",
495 1.11 cgd "[-M core] [-N system] [-W swap]",
496 1.11 cgd "ps [-L]");
497 1.1 cgd exit(1);
498 1.1 cgd }
499