mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-26 13:05:18 +01:00
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.
This commit is contained in:
parent
3656f85bbd
commit
73eb8310a9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=13020
@ -30,7 +30,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
|
||||
.\" $Id$
|
||||
.\" $Id: ps.1,v 1.4 1994/09/24 02:56:46 davidg Exp $
|
||||
.\"
|
||||
.Dd April 18, 1994
|
||||
.Dt PS 1
|
||||
@ -47,6 +47,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
|
||||
@ -130,6 +131,9 @@ with the standard input.
|
||||
.It Fl t
|
||||
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.
|
||||
|
17
bin/ps/ps.c
17
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();
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user