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.
+ the username of the task instead of its UID. When this option is
+ followed by a user name, then only tasks belonging to the
+ specified user are displayed by pidstat.
* pidstat manual page updated.
* Now use sigaction() instead of signal() for signals handling
to avoid portability problems.
.SH NAME
pidstat \- Report statistics for Linux tasks.
.SH SYNOPSIS
-.B pidstat [ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U ] [ -u ] [ -V ]
+.B pidstat [ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U [ username ] ] [ -u ] [ -V ]
.B [ -w ] [ -C
.I comm
.B ] [ -p {
The identification number of the thread being monitored.
.RE
.RE
+.IP "-U [ username ]"
+Display the real user name of the tasks being monitored instead of the UID.
+If
+.I username
+is specified, then only tasks belonging to the specified user are displayed.
.IP -u
Report CPU utilization.
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
struct pid_stats st_pid_null;
struct tm ps_tstamp[3];
char commstr[MAX_COMM_LEN];
+char userstr[MAX_USER_LEN];
unsigned int pid_nr = 0; /* Nb of PID to display */
unsigned int pid_array_nr = 0;
progname);
fprintf(stderr, _("Options are:\n"
- "[ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U ] [ -u ] [ -V ]\n"
- "[ -w ] [ -C <command> ] [ -p { <pid> [,...] | SELF | ALL } ]\n"
+ "[ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U [ username ] ] [ -u ]\n"
+ "[ -V ] [ -w ] [ -C <command> ] [ -p { <pid> [,...] | SELF | ALL } ]\n"
"[ -T { TASK | CHILD | ALL } ]\n"));
exit(1);
}
{
int q, rc;
regex_t regex;
+ struct passwd *pwdent;
*pstc = st_pid_list[curr] + p;
}
else if (DISPLAY_PID(pidflag)) {
-
*pstp = st_pid_list[prev] + p;
if (!(*pstp)->pid)
}
if (COMMAND_STRING(pidflag)) {
-
if (regcomp(®ex, commstr, REG_EXTENDED | REG_NOSUB) != 0)
/* Error in preparing regex structure */
return -1;
/* regex pattern not found in command name */
return -1;
}
+
+ if (USER_STRING(pidflag)) {
+ if ((pwdent = getpwuid((*pstc)->uid)) != NULL) {
+ if (strcmp(pwdent->pw_name, userstr))
+ /* This PID doesn't belong to user */
+ return -1;
+ }
+ }
return 1;
}
usage(argv[0]);
}
}
+
+ else if (!strcmp(argv[opt], "-U")) {
+ /* Display username instead of UID */
+ pidflag |= P_D_USERNAME;
+ if (argv[++opt] && (argv[opt][0] != '-') &&
+ (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) {
+ strncpy(userstr, argv[opt++], MAX_USER_LEN);
+ userstr[MAX_USER_LEN - 1] = '\0';
+ pidflag |= P_F_USERSTR;
+ if (!strlen(userstr)) {
+ usage(argv[0]);
+ }
+ }
+ }
else if (!strncmp(argv[opt], "-", 1)) {
for (i = 1; *(argv[opt] + i); i++) {
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 MAX_COMM_LEN 128
#define MAX_CMDLINE_LEN 128
+#define MAX_USER_LEN 32
/* Activities */
#define P_A_CPU 0x01
#define P_D_ONELINE 0x040
#define P_D_CMDLINE 0x080
#define P_D_USERNAME 0x100
+#define P_F_USERSTR 0x200
#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_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 USER_STRING(m) (((m) & P_F_USERSTR) == P_F_USERSTR)
#define F_NO_PID_IO 0x01