aboutsummaryrefslogtreecommitdiff
path: root/procps/ps.c
diff options
context:
space:
mode:
Diffstat (limited to 'procps/ps.c')
-rw-r--r--procps/ps.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/procps/ps.c b/procps/ps.c
index 3f7437b38..c54618248 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -18,17 +18,36 @@ enum { MAX_WIDTH = 2*1024 };
18 18
19#include <sys/times.h> /* for times() */ 19#include <sys/times.h> /* for times() */
20#ifndef AT_CLKTCK 20#ifndef AT_CLKTCK
21#define AT_CLKTCK 17 21# define AT_CLKTCK 17
22#endif 22#endif
23 23
24 24/* TODO:
25 * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
26 * specifies (for XSI-conformant systems) following default columns
27 * (l and f mark columns shown with -l and -f respectively):
28 * F l Flags (octal and additive) associated with the process (??)
29 * S l The state of the process
30 * UID f,l The user ID; the login name is printed with -f
31 * PID The process ID
32 * PPID f,l The parent process
33 * C f,l Processor utilization
34 * PRI l The priority of the process; higher numbers mean lower priority
35 * NI l Nice value
36 * ADDR l The address of the process
37 * SZ l The size in blocks of the core image of the process
38 * WCHAN l The event for which the process is waiting or sleeping
39 * STIME f Starting time of the process
40 * TTY The controlling terminal for the process
41 * TIME The cumulative execution time for the process
42 * CMD The command name; the full command line is shown with -f
43 */
25#if ENABLE_SELINUX 44#if ENABLE_SELINUX
26#define SELINUX_O_PREFIX "label," 45# define SELINUX_O_PREFIX "label,"
27#define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") 46# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args")
28#elif ENABLE_PLATFORM_MINGW32 47#elif ENABLE_PLATFORM_MINGW32
29#define DEFAULT_O_STR ("pid,comm") 48# define DEFAULT_O_STR ("pid,comm")
30#else 49#else
31#define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") 50# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args")
32#endif 51#endif
33 52
34typedef struct { 53typedef struct {
@@ -70,7 +89,8 @@ static ptrdiff_t find_elf_note(ptrdiff_t findme)
70{ 89{
71 ptrdiff_t *ep = (ptrdiff_t *) environ; 90 ptrdiff_t *ep = (ptrdiff_t *) environ;
72 91
73 while (*ep++); 92 while (*ep++)
93 continue;
74 while (*ep) { 94 while (*ep) {
75 if (ep[0] == findme) { 95 if (ep[0] == findme) {
76 return ep[1]; 96 return ep[1];
@@ -186,6 +206,11 @@ static void func_comm(char *buf, int size, const procps_status_t *ps)
186 safe_strncpy(buf, ps->comm, size+1); 206 safe_strncpy(buf, ps->comm, size+1);
187} 207}
188 208
209static void func_stat(char *buf, int size, const procps_status_t *ps)
210{
211 safe_strncpy(buf, ps->state, size+1);
212}
213
189static void func_args(char *buf, int size, const procps_status_t *ps) 214static void func_args(char *buf, int size, const procps_status_t *ps)
190{ 215{
191 read_cmdline(buf, size+1, ps->pid, ps->comm); 216 read_cmdline(buf, size+1, ps->pid, ps->comm);
@@ -302,7 +327,7 @@ static void func_pcpu(char *buf, int size, const procps_status_t *ps)
302*/ 327*/
303 328
304static const ps_out_t out_spec[] = { 329static const ps_out_t out_spec[] = {
305// Mandated by POSIX: 330/* Mandated by http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html: */
306#if !ENABLE_PLATFORM_MINGW32 331#if !ENABLE_PLATFORM_MINGW32
307 { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, 332 { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID },
308 { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, 333 { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID },
@@ -331,7 +356,8 @@ static const ps_out_t out_spec[] = {
331#if !ENABLE_PLATFORM_MINGW32 356#if !ENABLE_PLATFORM_MINGW32
332 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, 357 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY },
333 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, 358 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ },
334// Not mandated by POSIX, but useful: 359/* Not mandated, but useful: */
360 { 4 , "stat" ,"STAT" ,func_stat ,PSSCAN_STAT },
335 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, 361 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS },
336#endif 362#endif
337#if ENABLE_SELINUX 363#if ENABLE_SELINUX