This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
Re: [Patch] ps command returns 1 if PID not found
- From: Christopher Faylor <cgf-use-the-mailinglist-please at cygwin dot com>
- To: cygwin-patches at cygwin dot com
- Date: Wed, 16 Dec 2009 10:56:25 -0500
- Subject: Re: [Patch] ps command returns 1 if PID not found
- References: <b4864b490912082352s369fc0e4me50de3883d782100@mail.gmail.com>
- Reply-to: cygwin-patches at cygwin dot com
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;
}
-