This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add -p option to ps command


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)
 	  {

Attachment: cygwin-ug-net.sgml.patch
Description: Text document

Attachment: cygwin-ug-net.texi.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]