* ps.cc (longopts): Add --process option.

(opts): Add -p option.
	(usage): Mention -p/--process option.
	(main): Handle -p option.
	* utils.sgml: Describe -p/--process option.
This commit is contained in:
Corinna Vinschen 2006-02-16 11:17:19 +00:00
parent 5e8b96517c
commit df4f13b723
3 changed files with 24 additions and 4 deletions

View File

@ -1,3 +1,11 @@
2006-02-16 Jerry D. Hedden <jerry@hedden.us>
* ps.cc (longopts): Add --process option.
(opts): Add -p option.
(usage): Mention -p/--process option.
(main): Handle -p option.
* utils.sgml: Describe -p/--process option.
2006-02-15 Igor Peshansky <pechtcha@cs.nyu.edu> 2006-02-15 Igor Peshansky <pechtcha@cs.nyu.edu>
* regtool.cc (usage): Clarify help for "-K". * regtool.cc (usage): Clarify help for "-K".

View File

@ -29,6 +29,7 @@ static struct option longopts[] =
{"full", no_argument, NULL, 'f' }, {"full", no_argument, NULL, 'f' },
{"help", no_argument, NULL, 'h' }, {"help", no_argument, NULL, 'h' },
{"long", no_argument, NULL, 'l' }, {"long", no_argument, NULL, 'l' },
{"process", required_argument, NULL, 'p'},
{"summary", no_argument, NULL, 's' }, {"summary", no_argument, NULL, 's' },
{"user", required_argument, NULL, 'u'}, {"user", required_argument, NULL, 'u'},
{"version", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'v'},
@ -36,7 +37,7 @@ static struct option longopts[] =
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
static char opts[] = "aefhlsu:vW"; static char opts[] = "aefhlp:su:vW";
typedef BOOL (WINAPI *ENUMPROCESSMODULES)( typedef BOOL (WINAPI *ENUMPROCESSMODULES)(
HANDLE hProcess, // handle to the process HANDLE hProcess, // handle to the process
@ -200,7 +201,7 @@ static void
usage (FILE * stream, int status) usage (FILE * stream, int status)
{ {
fprintf (stream, "\ fprintf (stream, "\
Usage: %s [-aefls] [-u UID]\n\ Usage: %s [-aefls] [-u UID] [-p PID]\n\
Report process status\n\ Report process status\n\
\n\ \n\
-a, --all show processes of all users\n\ -a, --all show processes of all users\n\
@ -208,6 +209,7 @@ Report process status\n\
-f, --full show process uids, ppids\n\ -f, --full show process uids, ppids\n\
-h, --help output usage information and exit\n\ -h, --help output usage information and exit\n\
-l, --long show process uids, ppids, pgids, winpids\n\ -l, --long show process uids, ppids, pgids, winpids\n\
-p, --process show information for specified PID\n\
-s, --summary show process summary\n\ -s, --summary show process summary\n\
-u, --user list processes owned by UID\n\ -u, --user list processes owned by UID\n\
-v, --version output version information and exit\n\ -v, --version output version information and exit\n\
@ -244,7 +246,7 @@ int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
external_pinfo *p; external_pinfo *p;
int aflag, lflag, fflag, sflag, uid; int aflag, lflag, fflag, sflag, uid, proc_id;
cygwin_getinfo_types query = CW_GETPINFO; cygwin_getinfo_types query = CW_GETPINFO;
const char *dtitle = " PID TTY STIME COMMAND\n"; const char *dtitle = " PID TTY STIME COMMAND\n";
const char *dfmt = "%7d%4s%10s %s\n"; const char *dfmt = "%7d%4s%10s %s\n";
@ -256,6 +258,7 @@ main (int argc, char *argv[])
aflag = lflag = fflag = sflag = 0; aflag = lflag = fflag = sflag = 0;
uid = getuid (); uid = getuid ();
proc_id = -1;
lflag = 1; lflag = 1;
prog_name = strrchr (argv[0], '/'); prog_name = strrchr (argv[0], '/');
@ -281,6 +284,9 @@ main (int argc, char *argv[])
case 'l': case 'l':
lflag = 1; lflag = 1;
break; break;
case 'p':
proc_id = atoi (optarg);
break;
case 's': case 's':
sflag = 1; sflag = 1;
break; break;
@ -328,6 +334,9 @@ main (int argc, char *argv[])
(p = (external_pinfo *) cygwin_internal (query, pid | CW_NEXTPID)); (p = (external_pinfo *) cygwin_internal (query, pid | CW_NEXTPID));
pid = p->pid) pid = p->pid)
{ {
if ((proc_id > 0) && (p->pid != proc_id))
continue;
if (!aflag) if (!aflag)
if (p->version >= EXTERNAL_PINFO_VERSION_32_BIT) if (p->version >= EXTERNAL_PINFO_VERSION_32_BIT)
{ {

View File

@ -970,6 +970,7 @@ Report process status
-f, --full show process uids, ppids -f, --full show process uids, ppids
-h, --help output usage information and exit -h, --help output usage information and exit
-l, --long show process uids, ppids, pgids, winpids -l, --long show process uids, ppids, pgids, winpids
-p, --process show information for specified PID
-s, --summary show process summary -s, --summary show process summary
-u, --user list processes owned by UID -u, --user list processes owned by UID
-v, --version output version information and exit -v, --version output version information and exit
@ -1008,7 +1009,9 @@ usernames for UIDs. The <literal>-l</literal> option is the default display
mode, showing a "long" listing with all the above columns. The other display mode, showing a "long" listing with all the above columns. The other display
option is <literal>-s</literal>, which outputs a shorter listing of just option is <literal>-s</literal>, which outputs a shorter listing of just
PID, TTY, STIME, and COMMAND. The <literal>-u</literal> option allows you PID, TTY, STIME, and COMMAND. The <literal>-u</literal> option allows you
to show only processes owned by a specific user. The <literal>-W</literal> to show only processes owned by a specific user. The <literal>-p</literal>
option allows you to show information for only the process with the
specified PID. The <literal>-W</literal>
option causes <command>ps</command> show non-Cygwin Windows processes as option causes <command>ps</command> show non-Cygwin Windows processes as
well as Cygwin processes. The WINPID is also the PID, and they can be killed well as Cygwin processes. The WINPID is also the PID, and they can be killed
with the Cygwin <command>kill</command> command's <literal>-f</literal> with the Cygwin <command>kill</command> command's <literal>-f</literal>