Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-05-28 07:38:36 +0400
committerChristopher Faylor <me@cgf.cx>2002-05-28 07:38:36 +0400
commitad39fa8cb092eb6bb9ba5672f373751c89b1d4ff (patch)
tree160702c120c5c211f4a701b4a9f7ab22da0f1397 /winsup/utils/ps.cc
parent0c12979b72c7467ed66383555e7478755e67b0ed (diff)
* ps.cc (prog_name): New global variable.
(longopts): Ditto. (opts): Ditto. (usage): New function. (print_version): New function. (main): Accomodate longopts and new --help, --version options.
Diffstat (limited to 'winsup/utils/ps.cc')
-rw-r--r--winsup/utils/ps.cc88
1 files changed, 77 insertions, 11 deletions
diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc
index c32110b43..1db849915 100644
--- a/winsup/utils/ps.cc
+++ b/winsup/utils/ps.cc
@@ -1,6 +1,6 @@
/* ps.cc
- Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
+ Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
This file is part of Cygwin.
@@ -19,6 +19,25 @@ details. */
#include <tlhelp32.h>
#include <psapi.h>
+static const char version[] = "$Revision$";
+static char *prog_name;
+
+static struct option longopts[] =
+{
+ {"all", no_argument, NULL, 'a' },
+ {"everyone", no_argument, NULL, 'e' },
+ {"full", no_argument, NULL, 'f' },
+ {"help", no_argument, NULL, 'h' },
+ {"long", no_argument, NULL, 'l' },
+ {"summary", no_argument, NULL, 's' },
+ {"user", required_argument, NULL, 'u'},
+ {"version", no_argument, NULL, 'v'},
+ {"windows", no_argument, NULL, 'W'},
+ {NULL, 0, NULL, 0}
+};
+
+static char opts[] = "aefhlsu:vW";
+
typedef BOOL (WINAPI *ENUMPROCESSMODULES)(
HANDLE hProcess, // handle to the process
HMODULE * lphModule, // array to receive the module handles
@@ -177,6 +196,46 @@ ttynam (int ntty)
return buf;
}
+static void
+usage (FILE * stream, int status)
+{
+ fprintf (stream, "\
+Usage: %s [-aefls] [-u UID]\n\
+ -a, --all show processes of all users\n\
+ -e, --everyone show processes of all users\n\
+ -f, --full show process uids, ppids\n\
+ -h, --help output usage information and exit\n\
+ -l, --long show process uids, ppids, pgids, winpids\n\
+ -s, --summary show process summary\n\
+ -u, --user list processes owned by UID\n\
+ -v, --version output version information and exit\n\
+ -W, --windows show windows as well as cygwin processes\n\
+With options, %s outputs the long format by default\n", prog_name, prog_name);
+ exit (status);
+}
+
+static void
+print_version ()
+{
+ const char *v = strchr (version, ':');
+ int len;
+ if (!v)
+ {
+ v = "?";
+ len = 1;
+ }
+ else
+ {
+ v += 2;
+ len = strchr (v, ' ') - v;
+ }
+ printf ("\
+%s (cygwin) %.*s\n\
+Process Statistics\n\
+Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\
+Compiled on %s", prog_name, len, v, __DATE__);
+}
+
int
main (int argc, char *argv[])
{
@@ -195,7 +254,15 @@ main (int argc, char *argv[])
uid = getuid ();
lflag = 1;
- while ((ch = getopt (argc, argv, "aelfsu:W")) != -1)
+ prog_name = strrchr (argv[0], '/');
+ if (prog_name == NULL)
+ prog_name = strrchr (argv[0], '\\');
+ if (prog_name == NULL)
+ prog_name = argv[0];
+ else
+ prog_name++;
+
+ while ((ch = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
switch (ch)
{
case 'a':
@@ -205,6 +272,8 @@ main (int argc, char *argv[])
case 'f':
fflag = 1;
break;
+ case 'h':
+ usage (stdout, 0);
case 'l':
lflag = 1;
break;
@@ -221,25 +290,22 @@ main (int argc, char *argv[])
uid = pw->pw_uid;
else
{
- fprintf (stderr, "user %s unknown\n", optarg);
+ fprintf (stderr, "%s: user %s unknown\n", prog_name, optarg);
exit (1);
}
}
break;
+ case 'v':
+ print_version ();
+ exit (0);
+ break;
case 'W':
query = CW_GETPINFO_FULL;
aflag = 1;
break;
default:
- fprintf (stderr, "Usage %s [-aefl] [-u uid]\n", argv[0]);
- fprintf (stderr, "-f = show process uids, ppids\n");
- fprintf (stderr, "-l = show process uids, ppids, pgids, winpids\n");
- fprintf (stderr, "-u uid = list processes owned by uid\n");
- fprintf (stderr, "-a, -e = show processes of all users\n");
- fprintf (stderr, "-s = show process summary\n");
- fprintf (stderr, "-W = show windows as well as cygwin processes\n");
- exit (1);
+ usage (stderr, 1);
}
if (sflag)