From df4f13b723bdd3b8b5912501b11a7854c08a58c7 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 16 Feb 2006 11:17:19 +0000 Subject: [PATCH] * 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. --- winsup/utils/ChangeLog | 8 ++++++++ winsup/utils/ps.cc | 15 ++++++++++++--- winsup/utils/utils.sgml | 5 ++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index adf2218b7..10fe823ea 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,11 @@ +2006-02-16 Jerry D. Hedden + + * 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 * regtool.cc (usage): Clarify help for "-K". diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc index 12b60fd08..27203d0c7 100644 --- a/winsup/utils/ps.cc +++ b/winsup/utils/ps.cc @@ -29,6 +29,7 @@ static struct option longopts[] = {"full", no_argument, NULL, 'f' }, {"help", no_argument, NULL, 'h' }, {"long", no_argument, NULL, 'l' }, + {"process", required_argument, NULL, 'p'}, {"summary", no_argument, NULL, 's' }, {"user", required_argument, NULL, 'u'}, {"version", no_argument, NULL, 'v'}, @@ -36,7 +37,7 @@ static struct option longopts[] = {NULL, 0, NULL, 0} }; -static char opts[] = "aefhlsu:vW"; +static char opts[] = "aefhlp:su:vW"; typedef BOOL (WINAPI *ENUMPROCESSMODULES)( HANDLE hProcess, // handle to the process @@ -200,7 +201,7 @@ static void usage (FILE * stream, int status) { fprintf (stream, "\ -Usage: %s [-aefls] [-u UID]\n\ +Usage: %s [-aefls] [-u UID] [-p PID]\n\ Report process status\n\ \n\ -a, --all show processes of all users\n\ @@ -208,6 +209,7 @@ Report process status\n\ -f, --full show process uids, ppids\n\ -h, --help output usage information and exit\n\ -l, --long show process uids, ppids, pgids, winpids\n\ + -p, --process show information for specified PID\n\ -s, --summary show process summary\n\ -u, --user list processes owned by UID\n\ -v, --version output version information and exit\n\ @@ -244,7 +246,7 @@ int main (int argc, char *argv[]) { external_pinfo *p; - int aflag, lflag, fflag, sflag, uid; + int aflag, lflag, fflag, sflag, uid, proc_id; cygwin_getinfo_types query = CW_GETPINFO; const char *dtitle = " PID TTY STIME COMMAND\n"; const char *dfmt = "%7d%4s%10s %s\n"; @@ -256,6 +258,7 @@ main (int argc, char *argv[]) aflag = lflag = fflag = sflag = 0; uid = getuid (); + proc_id = -1; lflag = 1; prog_name = strrchr (argv[0], '/'); @@ -281,6 +284,9 @@ main (int argc, char *argv[]) case 'l': lflag = 1; break; + case 'p': + proc_id = atoi (optarg); + break; case 's': sflag = 1; break; @@ -328,6 +334,9 @@ main (int argc, char *argv[]) (p = (external_pinfo *) cygwin_internal (query, pid | CW_NEXTPID)); pid = p->pid) { + if ((proc_id > 0) && (p->pid != proc_id)) + continue; + if (!aflag) if (p->version >= EXTERNAL_PINFO_VERSION_32_BIT) { diff --git a/winsup/utils/utils.sgml b/winsup/utils/utils.sgml index aad186962..de6ab52c4 100644 --- a/winsup/utils/utils.sgml +++ b/winsup/utils/utils.sgml @@ -970,6 +970,7 @@ Report process status -f, --full show process uids, ppids -h, --help output usage information and exit -l, --long show process uids, ppids, pgids, winpids + -p, --process show information for specified PID -s, --summary show process summary -u, --user list processes owned by UID -v, --version output version information and exit @@ -1008,7 +1009,9 @@ usernames for UIDs. The -l option is the default display mode, showing a "long" listing with all the above columns. The other display option is -s, which outputs a shorter listing of just PID, TTY, STIME, and COMMAND. The -u option allows you -to show only processes owned by a specific user. The -W +to show only processes owned by a specific user. The -p +option allows you to show information for only the process with the +specified PID. The -W option causes ps show non-Cygwin Windows processes as well as Cygwin processes. The WINPID is also the PID, and they can be killed with the Cygwin kill command's -f -- 2.43.5