Attached is a patch to add a -p option to the ps command to show
information for only a single PID: ps -p PID
This option is available on other implementations of ps (e.g., Solaris).
Index: winsup/utils/ps.cc
===================================================================
--- ps.cc.orig 2006-02-13 17:19:24.000000000 -0500
+++ ps.cc 2006-02-13 17:53:20.000000000 -0500
@@ -29,6 +29,7 @@
{"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 @@
{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 @@
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 @@
-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 @@
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 @@
aflag = lflag = fflag = sflag = 0;
uid = getuid ();
+ proc_id = -1;
lflag = 1;
prog_name = strrchr (argv[0], '/');
@@ -281,6 +284,9 @@
case 'l':
lflag = 1;
break;
+ case 'p':
+ proc_id = atoi (optarg);
+ break;
case 's':
sflag = 1;
break;
@@ -328,6 +334,9 @@
(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)
{
--- cygwin-ug-net.sgml.orig 2006-02-14 08:59:42.000000000 -0500
+++ cygwin-ug-net.sgml 2006-02-14 09:01:38.000000000 -0500
@@ -3834,7 +3834,7 @@
<sect2 id="ps"><title>ps</title>
<screen>
-Usage: ps [-aefls] [-u UID]
+Usage: ps [-aefls] [-u UID] [-p PID]
Report process status
-a, --all show processes of all users
@@ -3842,6 +3842,7 @@
-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
@@ -3880,7 +3881,9 @@
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
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
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>
--- cygwin-ug-net.texi.orig 2006-02-14 09:03:06.000000000 -0500
+++ cygwin-ug-net.texi 2006-02-14 09:02:10.000000000 -0500
@@ -3873,7 +3873,7 @@
@example
-Usage: ps [-aefls] [-u UID]
+Usage: ps [-aefls] [-u UID] [-p PID]
Report process status
-a, --all show processes of all users
@@ -3881,6 +3881,7 @@
-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
@@ -3915,7 +3916,9 @@
mode, showing a "long" listing with all the above columns. The other display
option is @samp{-s}, which outputs a shorter listing of just
PID, TTY, STIME, and COMMAND. The @samp{-u} option allows you
-to show only processes owned by a specific user. The @samp{-W}
+to show only processes owned by a specific user. The @samp{-p}
+option allows you to show information for only the process with the
+specified PID. The @samp{-W}
option causes @code{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 @code{kill} command's @samp{-f}