diff options
author | Alex Feldman <alex@cvs.openbsd.org> | 1999-04-28 20:55:15 +0000 |
---|---|---|
committer | Alex Feldman <alex@cvs.openbsd.org> | 1999-04-28 20:55:15 +0000 |
commit | 02dd2d4e17e1058d112c34a4b221db908beb2d6a (patch) | |
tree | 5314677782dfcb756249a86e18889e427e067bbe /bin | |
parent | 990889cedd0ceea5429b9b4b61baacebac44f468 (diff) |
Implement -U <username> option from FreeBSD. Original code by Peter Wemm.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ps/ps.1 | 6 | ||||
-rw-r--r-- | bin/ps/ps.c | 22 |
2 files changed, 22 insertions, 6 deletions
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index d3f29793928..982e1f9b833 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ps.1,v 1.17 1999/02/01 07:53:15 d Exp $ +.\" $OpenBSD: ps.1,v 1.18 1999/04/28 20:55:14 alex Exp $ .\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 @@ -49,6 +49,7 @@ .Op Fl o Ar fmt .Op Fl p Ar pid .Op Fl t Ar tty +.Op Fl U Ar username .Op Fl W Ar swap .Nm ps .Op Fl L @@ -147,6 +148,9 @@ with the standard input. .It Fl t Ar tty Display information about processes attached to the specified terminal device. +.It Fl U +Display the processes belonging to the specified +.Tn username . .It Fl u Display information associated with the following keywords: user, pid, %cpu, %mem, vsz, rss, tt, state, start, time and command. diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 7e84c0038fd..d0eda88552d 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.c,v 1.10 1998/07/08 22:14:25 deraadt Exp $ */ +/* $OpenBSD: ps.c,v 1.11 1999/04/28 20:55:14 alex Exp $ */ /* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: ps.c,v 1.10 1998/07/08 22:14:25 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ps.c,v 1.11 1999/04/28 20:55:14 alex Exp $"; #endif #endif /* not lint */ @@ -56,6 +56,7 @@ static char rcsid[] = "$OpenBSD: ps.c,v 1.10 1998/07/08 22:14:25 deraadt Exp $"; #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/sysctl.h> +#include <sys/types.h> #include <ctype.h> #include <err.h> @@ -64,6 +65,7 @@ static char rcsid[] = "$OpenBSD: ps.c,v 1.10 1998/07/08 22:14:25 deraadt Exp $"; #include <kvm.h> #include <nlist.h> #include <paths.h> +#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -109,6 +111,7 @@ main(argc, argv) struct kinfo_proc *kp; struct varent *vent; struct winsize ws; + struct passwd *pwd; dev_t ttydev; pid_t pid; uid_t uid; @@ -133,7 +136,7 @@ main(argc, argv) ttydev = NODEV; memf = nlistf = swapf = NULL; while ((ch = getopt(argc, argv, - "acCeghjLlM:mN:O:o:p:rSTt:uvW:wx")) != EOF) + "acCeghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != EOF) switch((char)ch) { case 'a': all = 1; @@ -217,6 +220,14 @@ main(argc, argv) ttydev = sb.st_rdev; break; } + case 'U': + pwd = getpwnam(optarg); + if (pwd == NULL) + errx(1, "%s: no such user", optarg); + uid = pwd->pw_uid; + endpwent(); + xflg = 1; + break; case 'u': parsefmt(ufmt); sortby = SORTCPU; @@ -278,7 +289,8 @@ main(argc, argv) if (!fmt) parsefmt(dfmt); - if (!all && ttydev == NODEV && pid == -1) /* XXX - should be cleaner */ + /* XXX - should be cleaner */ + if (!all && ttydev == NODEV && pid == -1 && uid == (uid_t)-1) uid = getuid(); /* @@ -477,7 +489,7 @@ usage() (void)fprintf(stderr, "usage:\t%s\n\t %s\n\t%s\n", - "ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty]", + "ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty] [-U user]", "[-M core] [-N system] [-W swap]", "ps [-L]"); exit(1); |