delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/04/30/19:02:28

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Matthew Woehlke <mw_triad AT users DOT sourceforge DOT net>
Subject: Re: display ps command line parameters
Date: Mon, 30 Apr 2007 18:01:42 -0500
Lines: 91
Message-ID: <f15sgm$e0t$1@sea.gmane.org>
References: <4edba06c76Andy AT jet-net DOT co DOT uk> <loom DOT 20070430T174617-803 AT post DOT gmane DOT org> <f15a4e$9ml$1 AT sea DOT gmane DOT org> <045201c78b52$9f46e0b0$2e08a8c0 AT CAM DOT ARTIMI DOT COM> <f15c6n$gr4$1 AT sea DOT gmane DOT org> <045a01c78b55$04f20780$2e08a8c0 AT CAM DOT ARTIMI DOT COM>
Mime-Version: 1.0
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.4.0
In-Reply-To: <045a01c78b55$04f20780$2e08a8c0@CAM.ARTIMI.COM>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------000902040704050809040004
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Dave Korn wrote:
> On 30 April 2007 19:23, Matthew Woehlke wrote:
> 
>> Dave Korn wrote:
>>> On 30 April 2007 18:48, Matthew Woehlke wrote:
>>>
>>>> um... and since Cygwin has this information, doesn't this mean that 'ps'
>>>> is missing a feature that is standard to pretty much every other *nix
>>>> implementation of 'ps'? (I don't have a POSIX standard handy
>>>   Yes you do:  open browser, google "posix opengroup".  Vol.2, "Shell and
>>> utilities", part 4: Utilities: takes us to
>> ...and am too lazy to look. :-) Anyway, since the information is
>> available, and most other *nix's 'ps' provides it, any reason Cygwin's
>> 'ps' shouldn't do the same?
> 
>   I believe you can probably guess the answer to this one... particularly if I
> tell you it starts with "P" and ends with "TC"  :)

Ok... Here is a P for you to TD* (* D="Decline") :-)

-- 
Matthew
If you believe you received this e-mail in error, you are probably sadly 
mistaken, but if not, aren't you lucky?

--------------000902040704050809040004
Content-Type: text/x-patch;
 name="ps.cc.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ps.cc.diff"

--- ps.cc.orig	2007-04-30 17:33:46.245634000 -0500
+++ ps.cc	2007-04-30 17:57:22.907472200 -0500
@@ -18,6 +18,7 @@
 #include <sys/cygwin.h>
 #include <tlhelp32.h>
 #include <psapi.h>
+#include <sys/stat.h>

 static const char version[] = "$Revision: 1.11 $";
 static char *prog_name;
@@ -253,7 +254,7 @@
   const char *ftitle = "     UID     PID    PPID TTY     STIME COMMAND\n";
   const char *ffmt   = "%8.8s%8d%8d%4s%10s %s\n";
   const char *ltitle = "      PID    PPID    PGID     WINPID  TTY  UID    STIME COMMAND\n";
-  const char *lfmt   = "%c %7d %7d %7d %10u %4s %4u %8s %s\n";
+  const char *lfmt   = "%c %7d %7d %7d %10u %4s %4u %8s %s";
   char ch;

   aflag = lflag = fflag = sflag = 0;
@@ -405,11 +406,27 @@
 	printf (ffmt, uname, p->pid, p->ppid, ttynam (p->ctty), start_time (p),
 		pname);
       else if (lflag)
-	printf (lfmt, status, p->pid, p->ppid, p->pgid,
-		p->dwProcessId, ttynam (p->ctty),
-		p->version >= EXTERNAL_PINFO_VERSION_32_BIT ? p->uid32 : p->uid,
-		start_time (p), pname);
-
+	{
+	  printf (lfmt, status, p->pid, p->ppid, p->pgid,
+		  p->dwProcessId, ttynam (p->ctty),
+		  p->version >= EXTERNAL_PINFO_VERSION_32_BIT ? p->uid32 : p->uid,
+		  start_time (p), pname);
+	  if (p->ppid)
+	    {
+	      char procpath[MAX_PATH];
+	      FILE *f;
+	      snprintf(procpath, MAX_PATH, "/proc/%u/cmdline", p->pid);
+	      f = fopen(procpath, "rb");
+	      if (f)
+		{
+		  int c = 1;
+		  while (c != 0 && c != EOF) c = fgetc(f);
+		  for (;c != EOF; c = fgetc(f)) printf("%c", c?c:' ');
+		  fclose(f);
+		}
+	    }
+	  printf("\n");
+	}
     }
   (void) cygwin_internal (CW_UNLOCK_PINFO);



--------------000902040704050809040004
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--------------000902040704050809040004--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019