summaryrefslogtreecommitdiffstats
path: root/bin/ps/ps.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1995-12-26 03:38:55 +0000
committerpeter <peter@FreeBSD.org>1995-12-26 03:38:55 +0000
commit82fea0b00ef057090047916457f6c1e90c71d7f7 (patch)
tree16094aa2de13e455b746b74df12674e7b774980d /bin/ps/ps.c
parentdb42dac3f5b466d667b6c4b4d57565819b3d2f43 (diff)
downloadFreeBSD-src-82fea0b00ef057090047916457f6c1e90c71d7f7.zip
FreeBSD-src-82fea0b00ef057090047916457f6c1e90c71d7f7.tar.gz
Implement a new option to ps.. `-U username'. This allows you to
list the processes belonging to a particular user without having to use `-u' and grepping for the username. Basically you can now get a short `ps -x' like list (with more space for the command) for other users.
Diffstat (limited to 'bin/ps/ps.c')
-rw-r--r--bin/ps/ps.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index fae17b2..0899212 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ps.c,v 1.8 1995/10/23 21:06:31 ache Exp $
+ * $Id: ps.c,v 1.9 1995/10/26 10:57:52 ache Exp $
*/
#ifndef lint
@@ -64,6 +64,7 @@ static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94";
#include <string.h>
#include <unistd.h>
#include <locale.h>
+#include <pwd.h>
#include "ps.h"
@@ -110,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;
@@ -136,7 +138,7 @@ main(argc, argv)
ttydev = NODEV;
memf = nlistf = swapf = NULL;
while ((ch = getopt(argc, argv,
- "aCeghjLlM:mN:O:o:p:rSTt:uvW:wx")) != EOF)
+ "aCeghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != EOF)
switch((char)ch) {
case 'a':
all = 1;
@@ -217,6 +219,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++; /* XXX: intuitive? */
+ break;
case 'u':
parsefmt(ufmt);
sortby = SORTCPU;
@@ -274,7 +284,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();
/*
OpenPOWER on IntegriCloud