[Patch] ps command returns 1 if PID not found

Christopher Faylor cgf-use-the-mailinglist-please@cygwin.com
Wed Dec 16 15:56:00 GMT 2009


On Wed, Dec 09, 2009 at 06:52:14PM +1100, Ryan Dortmans wrote:
>Attached is a small patch for ps to return 1 if the option --process
>is passed and the PID is not found. This is the behaviour in other
>versions of ps.

Sorry but returning 1 doesn't make sense and it isn't the way that linux
works.  It actually returns 0.

I haven't tested this but it seems to do what you want.

cgf

Index: ps.cc
===================================================================
RCS file: /cvs/uberbaum/winsup/utils/ps.cc,v
retrieving revision 1.26
diff -d -u -r1.26 ps.cc
--- ps.cc	11 May 2009 14:01:17 -0000	1.26
+++ ps.cc	16 Dec 2009 15:56:20 -0000
@@ -258,6 +258,7 @@
 {
   external_pinfo *p;
   int aflag, lflag, fflag, sflag, uid, proc_id;
+  bool found_proc_id = true;
   cygwin_getinfo_types query = CW_GETPINFO;
   const char *dtitle = "    PID TTY     STIME COMMAND\n";
   const char *dfmt   = "%7d%4s%10s %s\n";
@@ -299,6 +300,7 @@
       case 'p':
 	proc_id = atoi (optarg);
 	aflag = 1;
+	found_proc_id = false;
 	break;
       case 's':
 	sflag = 1;
@@ -369,6 +371,8 @@
     {
       if ((proc_id > 0) && (p->pid != proc_id))
 	continue;
+      else
+	found_proc_id = true;
 
       if (aflag)
 	/* nothing to do */;
@@ -499,6 +503,5 @@
     }
   (void) cygwin_internal (CW_UNLOCK_PINFO);
 
-  return 0;
+  return found_proc_id ? 0 : 1;
 }
-



More information about the Cygwin-patches mailing list