From 348ec55b79ce0e15fe8f13aa03bc29d302d78330 Mon Sep 17 00:00:00 2001 From: seb Date: Fri, 1 Mar 2013 15:26:53 +0100 Subject: [PATCH] pidstat now displays task's UID. pidstat now displays the real user ID of every task being monitored. Its manual page has also been updated. --- CHANGES | 2 ++ man/pidstat.1 | 49 +++++++++++++++++++++++++++++++++++++++++++------ pidstat.c | 11 +++++++---- pidstat.h | 5 +++-- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 23a9075..07af587 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,8 @@ xxxx/xx/xx: Version 10.1.4 - Sebastien Godard (sysstat orange.fr) receives SIGINT (crtl/c). * sar now stops and displays its average stats when it receives SIGINT (crtl/c). + * pidstat now displays task's UID for all tasks. + * pidstat manual page updated. * FAQ updated. 2012/12/23: Version 10.1.3 - Sebastien Godard (sysstat orange.fr) diff --git a/man/pidstat.1 b/man/pidstat.1 index f8c8d9c..f93f67e 100644 --- a/man/pidstat.1 +++ b/man/pidstat.1 @@ -1,4 +1,4 @@ -.TH PIDSTAT 1 "JULY 2012" Linux "Linux User's Manual" -*- nroff -*- +.TH PIDSTAT 1 "MARCH 2013" Linux "Linux User's Manual" -*- nroff -*- .SH NAME pidstat \- Report statistics for Linux tasks. .SH SYNOPSIS @@ -66,8 +66,13 @@ This string can be a regular expression. Report I/O statistics (kernels 2.6.20 and later only). The following values are displayed: -.B PID +.B UID +.RS .RS +The real user identification number of the task being monitored. +.RE + +.B PID .RS The identification number of the task being monitored. .RE @@ -124,9 +129,14 @@ Report page faults and memory utilization. When reporting statistics for individual tasks, the following values are displayed: -.B PID +.B UID .RS .RS +The real user identification number of the task being monitored. +.RE + +.B PID +.RS The identification number of the task being monitored. .RE @@ -166,6 +176,12 @@ The command name of the task. When reporting global statistics for tasks and all their children, the following values are displayed: +.B UID +.RS +The real user identification number of the task which is being monitored +together with its children. +.RE + .B PID .RS The identification number of the task which is being monitored @@ -194,9 +210,14 @@ together with its children. Report stack utilization. The following values are displayed: -.B PID +.B UID .RS .RS +The real user identification number of the task being monitored. +.RE + +.B PID +.RS The identification number of the task being monitored. .RE @@ -259,8 +280,13 @@ Report CPU utilization. When reporting statistics for individual tasks, the following values are displayed: -.B PID +.B UID +.RS .RS +The real user identification number of the task being monitored. +.RE + +.B PID .RS The identification number of the task being monitored. .RE @@ -306,6 +332,12 @@ The command name of the task. When reporting global statistics for tasks and all their children, the following values are displayed: +.B UID +.RS +The real user identification number of the task which is being monitored +together with its children. +.RE + .B PID .RS The identification number of the task which is being monitored @@ -347,9 +379,14 @@ Print version number then exit. Report task switching activity (kernels 2.6.23 and later only). The following values are displayed: -.B PID +.B UID .RS .RS +The real user identification number of the task being monitored. +.RE + +.B PID +.RS The identification number of the task being monitored. .RE diff --git a/pidstat.c b/pidstat.c index 8c2fa9c..0e08558 100644 --- a/pidstat.c +++ b/pidstat.c @@ -385,7 +385,10 @@ int read_proc_pid_status(unsigned int pid, struct pid_stats *pst, while (fgets(line, 256, fp) != NULL) { - if (!strncmp(line, "voluntary_ctxt_switches:", 24)) { + if (!strncmp(line, "Uid:", 4)) { + sscanf(line + 5, "%d", &pst->uid); + } + else if (!strncmp(line, "voluntary_ctxt_switches:", 24)) { sscanf(line + 25, "%lu", &pst->nvcsw); } else if (!strncmp(line, "nonvoluntary_ctxt_switches:", 27)) { @@ -1090,7 +1093,7 @@ void __print_line_id(struct pid_stats *pst, char c) */ void print_line_id(char *timestamp, struct pid_stats *pst) { - printf("%-11s", timestamp); + printf("%-11s %5d", timestamp, pst->uid); __print_line_id(pst, '-'); } @@ -1146,7 +1149,7 @@ int write_pid_task_all_stats(int prev, int curr, int dis, &pstc, &pstp) <= 0) continue; - printf("%11ld", (long) time(NULL)); + printf("%11ld %5d", (long) time(NULL), pstc->uid); __print_line_id(pstc, '0'); if (DISPLAY_CPU(actflag)) { @@ -1251,7 +1254,7 @@ int write_pid_child_all_stats(int prev, int curr, int dis, &pstc, &pstp) <= 0) continue; - printf("%11ld", (long) time(NULL)); + printf("%11ld %5d", (long) time(NULL), pstc->uid); __print_line_id(pstc, '0'); if (DISPLAY_CPU(actflag)) { diff --git a/pidstat.h b/pidstat.h index c99cf7a..dd090a1 100644 --- a/pidstat.h +++ b/pidstat.h @@ -1,6 +1,6 @@ /* * pidstat: Display per-process statistics. - * (C) 2007-2011 by Sebastien Godard (sysstat orange.fr) + * (C) 2007-2013 by Sebastien Godard (sysstat orange.fr) */ #ifndef _PIDSTAT_H @@ -78,7 +78,7 @@ #define TASK_SMAP "/proc/%u/task/%u/smaps" #define PRINT_ID_HDR(_timestamp_, _flag_) do { \ - printf("\n%-11s", _timestamp_); \ + printf("\n%-11s UID", _timestamp_); \ if (DISPLAY_TID(_flag_)) { \ printf(" TGID TID"); \ } \ @@ -120,6 +120,7 @@ struct pid_stats { unsigned int uc_asum_count __attribute__ ((packed)); unsigned int processor __attribute__ ((packed)); unsigned int flags __attribute__ ((packed)); + unsigned int uid __attribute__ ((packed)); char comm[MAX_COMM_LEN]; char cmdline[MAX_CMDLINE_LEN]; }; -- 2.40.0