2000-02-18 03:38:33 +08:00
|
|
|
/* ps.cc
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
#include <errno.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdio.h>
|
2011-11-29 01:49:56 +08:00
|
|
|
#include <locale.h>
|
2009-05-11 22:01:17 +08:00
|
|
|
#include <wchar.h>
|
2000-05-19 02:39:11 +08:00
|
|
|
#include <windows.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pwd.h>
|
2007-12-07 02:26:18 +08:00
|
|
|
#include <limits.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <sys/cygwin.h>
|
2011-10-10 22:57:48 +08:00
|
|
|
#include <cygwin/version.h>
|
2011-12-22 21:48:05 +08:00
|
|
|
#include <psapi.h>
|
2012-07-06 22:52:33 +08:00
|
|
|
#include <ntdef.h>
|
|
|
|
#include <ntdll.h>
|
2010-08-28 19:22:37 +08:00
|
|
|
#include "loadlib.h"
|
2000-07-30 00:26:37 +08:00
|
|
|
|
2008-03-12 20:47:09 +08:00
|
|
|
/* Maximum possible path length under NT. There's no official define
|
|
|
|
for that value. Note that PATH_MAX is only 4K. */
|
2019-03-13 03:55:24 +08:00
|
|
|
#define NT_MAX_PATH 32767
|
2008-03-12 20:47:09 +08:00
|
|
|
|
2002-05-28 11:38:36 +08:00
|
|
|
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' },
|
2006-02-16 19:17:19 +08:00
|
|
|
{"process", required_argument, NULL, 'p'},
|
2002-05-28 11:38:36 +08:00
|
|
|
{"summary", no_argument, NULL, 's' },
|
|
|
|
{"user", required_argument, NULL, 'u'},
|
2011-10-10 22:57:48 +08:00
|
|
|
{"version", no_argument, NULL, 'V'},
|
2002-05-28 11:38:36 +08:00
|
|
|
{"windows", no_argument, NULL, 'W'},
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
static char opts[] = "aefhlp:su:VW";
|
2002-05-28 11:38:36 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
static char *
|
|
|
|
start_time (external_pinfo *child)
|
|
|
|
{
|
|
|
|
time_t st = child->start_time;
|
|
|
|
time_t t = time (NULL);
|
|
|
|
static char stime[40] = {'\0'};
|
|
|
|
char now[40];
|
|
|
|
|
|
|
|
strncpy (stime, ctime (&st) + 4, 15);
|
|
|
|
strcpy (now, ctime (&t) + 4);
|
|
|
|
|
|
|
|
if ((t - st) < (24 * 3600))
|
|
|
|
return (stime + 7);
|
|
|
|
|
|
|
|
stime[6] = '\0';
|
|
|
|
|
|
|
|
return stime;
|
|
|
|
}
|
|
|
|
|
2000-07-30 00:26:37 +08:00
|
|
|
#define FACTOR (0x19db1ded53ea710LL)
|
|
|
|
#define NSPERSEC 10000000LL
|
|
|
|
|
|
|
|
/* Convert a Win32 time to "UNIX" format. */
|
|
|
|
long __stdcall
|
|
|
|
to_time_t (FILETIME *ptr)
|
|
|
|
{
|
|
|
|
/* A file time is the number of 100ns since jan 1 1601
|
|
|
|
stuffed into two long words.
|
|
|
|
A time_t is the number of seconds since jan 1 1970. */
|
|
|
|
|
|
|
|
long rem;
|
|
|
|
long long x = ((long long) ptr->dwHighDateTime << 32) + ((unsigned)ptr->dwLowDateTime);
|
|
|
|
x -= FACTOR; /* number of 100ns between 1601 and 1970 */
|
|
|
|
rem = x % ((long long)NSPERSEC);
|
|
|
|
rem += (NSPERSEC / 2);
|
|
|
|
x /= (long long) NSPERSEC; /* number of 100ns in a second */
|
|
|
|
x += (long long) (rem / NSPERSEC);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2001-04-29 10:32:18 +08:00
|
|
|
static const char *
|
2020-02-27 04:08:51 +08:00
|
|
|
ttynam (int ntty, char buf[9])
|
2001-04-29 10:32:18 +08:00
|
|
|
{
|
2011-05-29 23:20:10 +08:00
|
|
|
char buf0[9];
|
2020-02-27 04:08:51 +08:00
|
|
|
|
2001-04-29 10:32:18 +08:00
|
|
|
if (ntty < 0)
|
2011-05-29 23:20:10 +08:00
|
|
|
strcpy (buf0, "?");
|
|
|
|
else if (ntty & 0xffff0000)
|
2020-02-27 04:08:51 +08:00
|
|
|
snprintf (buf0, 9, "cons%d", ntty & 0xff);
|
2011-05-29 23:20:10 +08:00
|
|
|
else
|
2020-02-27 04:08:51 +08:00
|
|
|
snprintf (buf0, 9, "pty%d", ntty);
|
|
|
|
snprintf (buf, 9, " %-7.7s", buf0);
|
2001-04-29 10:32:18 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2020-08-07 19:29:43 +08:00
|
|
|
static void __attribute__ ((__noreturn__))
|
2002-05-28 11:38:36 +08:00
|
|
|
usage (FILE * stream, int status)
|
|
|
|
{
|
|
|
|
fprintf (stream, "\
|
2011-10-10 22:57:48 +08:00
|
|
|
Usage: %1$s [-aefls] [-u UID] [-p PID]\n\
|
|
|
|
\n\
|
2003-04-27 05:52:03 +08:00
|
|
|
Report process status\n\
|
|
|
|
\n\
|
2002-05-28 11:38:36 +08:00
|
|
|
-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\
|
2006-02-16 19:17:19 +08:00
|
|
|
-p, --process show information for specified PID\n\
|
2002-05-28 11:38:36 +08:00
|
|
|
-s, --summary show process summary\n\
|
|
|
|
-u, --user list processes owned by UID\n\
|
2011-10-10 22:57:48 +08:00
|
|
|
-V, --version output version information and exit\n\
|
2002-05-28 11:38:36 +08:00
|
|
|
-W, --windows show windows as well as cygwin processes\n\
|
2011-10-10 22:57:48 +08:00
|
|
|
\n\
|
|
|
|
With no options, %1$s outputs the long format by default\n\n",
|
|
|
|
prog_name);
|
2002-05-28 11:38:36 +08:00
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
2011-10-10 22:57:48 +08:00
|
|
|
printf ("ps (cygwin) %d.%d.%d\n"
|
2011-12-18 07:39:47 +08:00
|
|
|
"Show process statistics\n"
|
2016-05-24 17:16:39 +08:00
|
|
|
"Copyright (C) 1996 - %s Cygwin Authors\n"
|
2011-12-18 07:39:47 +08:00
|
|
|
"This is free software; see the source for copying conditions. There is NO\n"
|
2011-10-10 22:57:48 +08:00
|
|
|
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
|
2011-12-18 07:39:47 +08:00
|
|
|
CYGWIN_VERSION_DLL_MAJOR / 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MAJOR % 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MINOR,
|
|
|
|
strrchr (__DATE__, ' ') + 1);
|
2002-05-28 11:38:36 +08:00
|
|
|
}
|
|
|
|
|
2019-03-13 03:55:24 +08:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
SYSTEM_PROCESS_ID_INFORMATION spii;
|
|
|
|
WCHAR buf[NT_MAX_PATH + 1];
|
|
|
|
} ucbuf;
|
|
|
|
|
|
|
|
char pname[NT_MAX_PATH + sizeof (" <defunct>") + 1];
|
2009-05-11 22:01:17 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
external_pinfo *p;
|
2013-04-23 17:44:36 +08:00
|
|
|
int aflag, lflag, fflag, sflag, proc_id;
|
|
|
|
uid_t uid;
|
2009-12-18 11:34:59 +08:00
|
|
|
bool found_proc_id = true;
|
2000-07-30 00:26:37 +08:00
|
|
|
cygwin_getinfo_types query = CW_GETPINFO;
|
2011-05-29 23:20:10 +08:00
|
|
|
const char *dtitle = " PID TTY STIME COMMAND\n";
|
2001-04-29 10:32:18 +08:00
|
|
|
const char *dfmt = "%7d%4s%10s %s\n";
|
2011-05-29 23:20:10 +08:00
|
|
|
const char *ftitle = " UID PID PPID TTY STIME COMMAND\n";
|
2001-04-29 10:32:18 +08:00
|
|
|
const char *ffmt = "%8.8s%8d%8d%4s%10s %s\n";
|
2015-06-10 17:07:27 +08:00
|
|
|
const char *ltitle = " PID PPID PGID WINPID TTY UID STIME COMMAND\n";
|
|
|
|
const char *lfmt = "%c %7d %7d %7d %10u %4s %8u %8s %s\n";
|
2000-02-18 03:38:33 +08:00
|
|
|
char ch;
|
2011-12-22 20:40:26 +08:00
|
|
|
void *drive_map = NULL;
|
2019-03-24 10:22:39 +08:00
|
|
|
time_t boot_time = -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-30 00:26:37 +08:00
|
|
|
aflag = lflag = fflag = sflag = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
uid = getuid ();
|
2006-02-16 19:17:19 +08:00
|
|
|
proc_id = -1;
|
2000-07-30 00:26:37 +08:00
|
|
|
lflag = 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-11-29 01:49:56 +08:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
prog_name = program_invocation_short_name;
|
2002-05-28 11:38:36 +08:00
|
|
|
|
|
|
|
while ((ch = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
2000-02-18 03:38:33 +08:00
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
case 'e':
|
2004-10-25 23:49:36 +08:00
|
|
|
aflag = 1;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case 'f':
|
2004-10-25 23:49:36 +08:00
|
|
|
fflag = 1;
|
|
|
|
break;
|
2002-05-28 11:38:36 +08:00
|
|
|
case 'h':
|
2004-10-25 23:49:36 +08:00
|
|
|
usage (stdout, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
case 'l':
|
2004-10-25 23:49:36 +08:00
|
|
|
lflag = 1;
|
|
|
|
break;
|
2006-02-16 19:17:19 +08:00
|
|
|
case 'p':
|
|
|
|
proc_id = atoi (optarg);
|
2006-02-17 19:16:23 +08:00
|
|
|
aflag = 1;
|
2009-12-18 11:34:59 +08:00
|
|
|
found_proc_id = false;
|
2006-02-16 19:17:19 +08:00
|
|
|
break;
|
2000-07-30 00:26:37 +08:00
|
|
|
case 's':
|
|
|
|
sflag = 1;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case 'u':
|
2004-10-25 23:49:36 +08:00
|
|
|
uid = atoi (optarg);
|
|
|
|
if (uid == 0)
|
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
if ((pw = getpwnam (optarg)))
|
|
|
|
uid = pw->pw_uid;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s: user %s unknown\n", prog_name, optarg);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-10-10 22:57:48 +08:00
|
|
|
case 'V':
|
2004-10-25 23:49:36 +08:00
|
|
|
print_version ();
|
|
|
|
exit (0);
|
|
|
|
break;
|
2000-07-30 00:26:37 +08:00
|
|
|
case 'W':
|
|
|
|
query = CW_GETPINFO_FULL;
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
default:
|
2011-10-10 22:57:48 +08:00
|
|
|
fprintf (stderr, "Try `%s --help' for more information.\n", prog_name);
|
|
|
|
exit (1);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-07-30 00:26:37 +08:00
|
|
|
if (sflag)
|
2018-08-09 14:41:18 +08:00
|
|
|
fputs (dtitle, stdout);
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (fflag)
|
2018-08-09 14:41:18 +08:00
|
|
|
fputs (ftitle, stdout);
|
2000-07-30 00:26:37 +08:00
|
|
|
else if (lflag)
|
2018-08-09 14:41:18 +08:00
|
|
|
fputs (ltitle, stdout);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
(void) cygwin_internal (CW_LOCK_PINFO, 1000);
|
|
|
|
|
2009-05-11 22:01:17 +08:00
|
|
|
if (query == CW_GETPINFO_FULL)
|
|
|
|
{
|
2019-03-24 10:22:39 +08:00
|
|
|
HANDLE tok;
|
|
|
|
NTSTATUS status;
|
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION stodi;
|
|
|
|
|
2009-05-11 22:01:17 +08:00
|
|
|
/* Enable debug privilege to allow to enumerate all processes,
|
|
|
|
not only processes in current session. */
|
|
|
|
if (OpenProcessToken (GetCurrentProcess (),
|
|
|
|
TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
|
|
|
|
&tok))
|
|
|
|
{
|
|
|
|
TOKEN_PRIVILEGES priv;
|
|
|
|
|
|
|
|
priv.PrivilegeCount = 1;
|
|
|
|
if (LookupPrivilegeValue (NULL, SE_DEBUG_NAME,
|
|
|
|
&priv.Privileges[0].Luid))
|
|
|
|
{
|
|
|
|
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
|
|
|
AdjustTokenPrivileges (tok, FALSE, &priv, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 21:48:05 +08:00
|
|
|
|
2015-06-10 17:07:27 +08:00
|
|
|
drive_map = (void *) cygwin_internal (CW_ALLOC_DRIVE_MAP);
|
2019-03-24 10:22:39 +08:00
|
|
|
|
|
|
|
/* Get system boot time to default process start time */
|
|
|
|
status = NtQuerySystemInformation (SystemTimeOfDayInformation,
|
|
|
|
(PVOID) &stodi, sizeof stodi, NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
fprintf (stderr,
|
2019-08-12 23:29:59 +08:00
|
|
|
"NtQuerySystemInformation(SystemTimeOfDayInformation), "
|
|
|
|
"status %#010x\n", (unsigned int) status);
|
2019-03-24 10:22:39 +08:00
|
|
|
boot_time = to_time_t ((FILETIME*)&stodi.BootTime);
|
2009-05-11 22:01:17 +08:00
|
|
|
}
|
2000-07-30 00:26:37 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
for (int pid = 0;
|
2000-07-30 00:26:37 +08:00
|
|
|
(p = (external_pinfo *) cygwin_internal (query, pid | CW_NEXTPID));
|
2000-02-18 03:38:33 +08:00
|
|
|
pid = p->pid)
|
|
|
|
{
|
2006-02-16 19:17:19 +08:00
|
|
|
if ((proc_id > 0) && (p->pid != proc_id))
|
|
|
|
continue;
|
2009-12-18 11:34:59 +08:00
|
|
|
else
|
|
|
|
found_proc_id = true;
|
2006-02-16 19:17:19 +08:00
|
|
|
|
2008-09-13 06:43:10 +08:00
|
|
|
if (aflag)
|
|
|
|
/* nothing to do */;
|
|
|
|
else if (p->version >= EXTERNAL_PINFO_VERSION_32_BIT)
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
if (p->uid32 != uid)
|
2008-09-13 06:43:10 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (p->uid != uid)
|
|
|
|
continue;
|
2000-02-18 03:38:33 +08:00
|
|
|
char status = ' ';
|
|
|
|
if (p->process_state & PID_STOPPED)
|
2004-10-25 23:49:36 +08:00
|
|
|
status = 'S';
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (p->process_state & PID_TTYIN)
|
2004-10-25 23:49:36 +08:00
|
|
|
status = 'I';
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (p->process_state & PID_TTYOU)
|
2004-10-25 23:49:36 +08:00
|
|
|
status = 'O';
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-08-11 03:52:41 +08:00
|
|
|
if (p->ppid)
|
2000-07-30 00:26:37 +08:00
|
|
|
{
|
|
|
|
char *s;
|
2000-08-25 03:03:12 +08:00
|
|
|
pname[0] = '\0';
|
2011-11-29 01:49:56 +08:00
|
|
|
strncat (pname, p->progname_long, NT_MAX_PATH);
|
2000-07-30 00:26:37 +08:00
|
|
|
s = strchr (pname, '\0') - 4;
|
|
|
|
if (s > pname && strcasecmp (s, ".exe") == 0)
|
|
|
|
*s = '\0';
|
2011-08-11 03:52:41 +08:00
|
|
|
if (p->process_state & PID_EXITED || (p->exitcode & ~0xffff))
|
|
|
|
strcat (pname, " <defunct>");
|
2000-07-30 00:26:37 +08:00
|
|
|
}
|
2011-12-22 21:48:05 +08:00
|
|
|
else if (query == CW_GETPINFO_FULL)
|
2000-07-30 00:26:37 +08:00
|
|
|
{
|
2011-12-22 20:40:26 +08:00
|
|
|
HANDLE h;
|
|
|
|
NTSTATUS status;
|
|
|
|
wchar_t *win32path = NULL;
|
2019-03-13 04:21:13 +08:00
|
|
|
FILETIME ct, et, kt, ut;
|
2011-12-22 20:40:26 +08:00
|
|
|
|
2019-03-13 04:21:13 +08:00
|
|
|
ucbuf.spii.ProcessId = (PVOID) (ULONG_PTR) p->dwProcessId;
|
|
|
|
ucbuf.spii.ImageName.Length = 0;
|
|
|
|
ucbuf.spii.ImageName.MaximumLength = NT_MAX_PATH * sizeof (WCHAR);
|
|
|
|
ucbuf.spii.ImageName.Buffer = ucbuf.buf;
|
|
|
|
status = NtQuerySystemInformation (SystemProcessIdInformation,
|
|
|
|
&ucbuf.spii, sizeof ucbuf.spii,
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS (status))
|
2011-12-22 21:48:05 +08:00
|
|
|
{
|
2019-03-13 04:21:13 +08:00
|
|
|
if (ucbuf.spii.ImageName.Length)
|
|
|
|
ucbuf.spii.ImageName.Buffer[ucbuf.spii.ImageName.Length
|
|
|
|
/ sizeof (WCHAR)] = L'\0';
|
|
|
|
win32path = ucbuf.spii.ImageName.Buffer;
|
2011-12-22 21:48:05 +08:00
|
|
|
}
|
2011-12-22 20:40:26 +08:00
|
|
|
if (win32path)
|
2019-03-13 03:55:24 +08:00
|
|
|
{
|
|
|
|
/* Call CW_MAP_DRIVE_MAP to convert native NT device paths to
|
2019-03-13 04:21:13 +08:00
|
|
|
an ordinary Win32 path. The returned pointer points into
|
|
|
|
the incoming buffer given as third argument. */
|
2019-03-13 03:55:24 +08:00
|
|
|
if (win32path[0] == L'\\')
|
|
|
|
win32path = (wchar_t *) cygwin_internal (CW_MAP_DRIVE_MAP,
|
|
|
|
drive_map, win32path);
|
|
|
|
wcstombs (pname, win32path, sizeof pname);
|
|
|
|
}
|
2011-11-29 01:49:56 +08:00
|
|
|
else
|
2019-03-13 03:55:24 +08:00
|
|
|
strcpy (pname, p->dwProcessId == 4 ? "System" : "*** unknown ***");
|
2019-03-13 04:21:13 +08:00
|
|
|
|
|
|
|
h = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION, FALSE,
|
|
|
|
p->dwProcessId);
|
2019-03-13 03:55:24 +08:00
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
if (GetProcessTimes (h, &ct, &et, &kt, &ut))
|
|
|
|
p->start_time = to_time_t (&ct);
|
|
|
|
CloseHandle (h);
|
|
|
|
}
|
2019-03-24 10:22:39 +08:00
|
|
|
/* Default to boot time when process start time inaccessible, 0, -1 */
|
2019-03-24 10:22:38 +08:00
|
|
|
if (!h || 0 == p->start_time || -1 == p->start_time)
|
|
|
|
{
|
2019-03-24 10:22:39 +08:00
|
|
|
p->start_time = boot_time;
|
2019-03-24 10:22:38 +08:00
|
|
|
}
|
2000-07-30 00:26:37 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
char uname[128];
|
2020-02-27 04:08:51 +08:00
|
|
|
char ttyname[9];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (fflag)
|
2004-10-25 23:49:36 +08:00
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
if ((pw = getpwuid (p->version >= EXTERNAL_PINFO_VERSION_32_BIT ?
|
|
|
|
p->uid32 : p->uid)))
|
|
|
|
strcpy (uname, pw->pw_name);
|
|
|
|
else
|
|
|
|
sprintf (uname, "%u", (unsigned)
|
|
|
|
(p->version >= EXTERNAL_PINFO_VERSION_32_BIT ?
|
2002-05-30 04:10:27 +08:00
|
|
|
p->uid32 : p->uid));
|
2004-10-25 23:49:36 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-30 00:26:37 +08:00
|
|
|
if (sflag)
|
2020-02-27 04:08:51 +08:00
|
|
|
printf (dfmt, p->pid, ttynam (p->ctty, ttyname), start_time (p), pname);
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (fflag)
|
2020-02-27 04:08:51 +08:00
|
|
|
printf (ffmt, uname, p->pid, p->ppid, ttynam (p->ctty, ttyname),
|
|
|
|
start_time (p), pname);
|
2000-07-30 00:26:37 +08:00
|
|
|
else if (lflag)
|
2004-10-25 23:49:36 +08:00
|
|
|
printf (lfmt, status, p->pid, p->ppid, p->pgid,
|
2020-02-27 04:08:51 +08:00
|
|
|
p->dwProcessId, ttynam (p->ctty, ttyname),
|
2002-05-30 04:10:27 +08:00
|
|
|
p->version >= EXTERNAL_PINFO_VERSION_32_BIT ? p->uid32 : p->uid,
|
|
|
|
start_time (p), pname);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
}
|
2011-12-22 20:40:26 +08:00
|
|
|
if (drive_map)
|
|
|
|
cygwin_internal (CW_FREE_DRIVE_MAP, drive_map);
|
2000-02-18 03:38:33 +08:00
|
|
|
(void) cygwin_internal (CW_UNLOCK_PINFO);
|
|
|
|
|
2009-12-18 11:34:59 +08:00
|
|
|
return found_proc_id ? 0 : 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|