* sar now stops and displays its average stats when it receives
SIGINT (crtl/c).
* pidstat now displays task's UID for all tasks.
+ * pidstat: -U option added. This option tells pidstat to display
+ the username of the task instead of its UID.
* pidstat manual page updated.
* FAQ updated.
.SH NAME
pidstat \- Report statistics for Linux tasks.
.SH SYNOPSIS
-.B pidstat [ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -u ] [ -V ]
+.B pidstat [ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U ] [ -u ] [ -V ]
.B [ -w ] [ -C
.I comm
.B ] [ -p {
This string can be a regular expression.
.IP -d
Report I/O statistics (kernels 2.6.20 and later only).
-The following values are displayed:
+The following values may be displayed:
.B UID
.RS
The real user identification number of the task being monitored.
.RE
+.B USER
+.RS
+The real user name of the task being monitored.
+.RE
+
.B PID
.RS
The identification number of the task being monitored.
Report page faults and memory utilization.
When reporting statistics for individual tasks,
-the following values are displayed:
+the following values may be displayed:
.B UID
.RS
The real user identification number of the task being monitored.
.RE
+.B USER
+.RS
+The real user name of the task being monitored.
+.RE
+
.B PID
.RS
The identification number of the task being monitored.
.RE
When reporting global statistics for tasks and all their children,
-the following values are displayed:
+the following values may be displayed:
.B UID
.RS
together with its children.
.RE
+.B USER
+.RS
+The real user name 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
.RE
.IP -s
Report stack utilization.
-The following values are displayed:
+The following values may be displayed:
.B UID
.RS
The real user identification number of the task being monitored.
.RE
+.B USER
+.RS
+The real user name of the task being monitored.
+.RE
+
.B PID
.RS
The identification number of the task being monitored.
Report CPU utilization.
When reporting statistics for individual tasks,
-the following values are displayed:
+the following values may be displayed:
.B UID
.RS
The real user identification number of the task being monitored.
.RE
+.B USER
+.RS
+The real user name of the task being monitored.
+.RE
+
.B PID
.RS
The identification number of the task being monitored.
.RE
When reporting global statistics for tasks and all their children,
-the following values are displayed:
+the following values may be displayed:
.B UID
.RS
together with its children.
.RE
+.B USER
+.RS
+The real user name 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
together with its children.
.RE
.RE
+.IP -U
+Display the real user name of the tasks being monitored instead of the UID.
.IP -V
Print version number then exit.
.IP -w
Report task switching activity (kernels 2.6.23 and later only).
-The following values are displayed:
+The following values may be displayed:
.B UID
.RS
The real user identification number of the task being monitored.
.RE
+.B USER
+.RS
+The real user name of the task being monitored.
+.RE
+
.B PID
.RS
The identification number of the task being monitored.
#include <dirent.h>
#include <ctype.h>
#include <sys/types.h>
+#include <pwd.h>
#include <sys/utsname.h>
#include <regex.h>
progname);
fprintf(stderr, _("Options are:\n"
- "[ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -u ] [ -V ]\n"
+ "[ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U ] [ -u ] [ -V ]\n"
"[ -w ] [ -C <command> ] [ -p { <pid> [,...] | SELF | ALL } ]\n"
"[ -T { TASK | CHILD | ALL } ]\n"));
exit(1);
/*
***************************************************************************
- * Display PID and TID.
+ * Display UID/username, PID and TID.
*
* IN:
* @pst Current process statistics.
void __print_line_id(struct pid_stats *pst, char c)
{
char format[32];
+ struct passwd *pwdent;
+ if (DISPLAY_USERNAME(pidflag) && ((pwdent = getpwuid(pst->uid)) != NULL)) {
+ printf(" %8s", pwdent->pw_name);
+ }
+ else {
+ printf(" %5d", pst->uid);
+ }
+
if (DISPLAY_TID(pidflag)) {
if (pst->tgid) {
*/
void print_line_id(char *timestamp, struct pid_stats *pst)
{
- printf("%-11s %5d", timestamp, pst->uid);
+ printf("%-11s", timestamp);
__print_line_id(pst, '-');
}
&pstc, &pstp) <= 0)
continue;
- printf("%11ld %5d", (long) time(NULL), pstc->uid);
+ printf("%11ld", (long) time(NULL));
__print_line_id(pstc, '0');
if (DISPLAY_CPU(actflag)) {
&pstc, &pstp) <= 0)
continue;
- printf("%11ld %5d", (long) time(NULL), pstc->uid);
+ printf("%11ld", (long) time(NULL));
__print_line_id(pstc, '0');
if (DISPLAY_CPU(actflag)) {
pidflag |= P_D_TID;
break;
+ case 'U':
+ /* Display username instead of UID */
+ pidflag |= P_D_USERNAME;
+ break;
+
case 'u':
/* Display CPU usage */
actflag |= P_A_CPU;
#define P_D_TID 0x020
#define P_D_ONELINE 0x040
#define P_D_CMDLINE 0x080
+#define P_D_USERNAME 0x100
#define DISPLAY_PID(m) (((m) & P_D_PID) == P_D_PID)
#define DISPLAY_ALL_PID(m) (((m) & P_D_ALL_PID) == P_D_ALL_PID)
#define DISPLAY_TID(m) (((m) & P_D_TID) == P_D_TID)
#define DISPLAY_ONELINE(m) (((m) & P_D_ONELINE) == P_D_ONELINE)
#define DISPLAY_CMDLINE(m) (((m) & P_D_CMDLINE) == P_D_CMDLINE)
+#define DISPLAY_USERNAME(m) (((m) & P_D_USERNAME) == P_D_USERNAME)
#define F_NO_PID_IO 0x01
#define TASK_SMAP "/proc/%u/task/%u/smaps"
#define PRINT_ID_HDR(_timestamp_, _flag_) do { \
- printf("\n%-11s UID", _timestamp_); \
+ printf("\n%-11s", _timestamp_); \
+ if (DISPLAY_USERNAME(_flag_)) { \
+ printf(" USER"); \
+ } \
+ else { \
+ printf(" UID"); \
+ } \
if (DISPLAY_TID(_flag_)) { \
printf(" TGID TID"); \
} \