Red Hat Bugzilla – Bug 88981
"ps" does not consistently translate UIDs to usernames against NIS users
Last modified: 2007-04-18 12:53:06 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2)
Description of problem:
When I am running "ps" to see the process owners in the system, sometimes UIDs
are not translated to usernames. This is becoming a problem as I am having to
institute process monitoring to see who is abusing our systems, and some
processes are shown with only a UID, other processes are shown using the
username. We use NIS for distributing our user accounts, so that might be
Here are some of the other software versions which might be interacting with the
Version-Release number of selected component (if applicable):
Steps to Reproduce:
Here's some snippets showing you what's going on.
[root@stratus root]# ps -ea --format "%p %u %c" | grep rhalbhav | wc -l
[root@stratus root]# ypcat passwd | grep rhalbhav
[root@stratus root]# ps -ea --format "%p %u %c" | grep 2193 | wc -l
After running strace and ltrace on the "ps" command, I cannot determine anything
other than the fact (which I knew) that it's getting it's information from the
/proc filesystem. I cannot find any indication that there is something different
for users that "ps" is not translating UIDs for in the /proc filesystem.
Actual Results: Some processes show up with numeric UIDs, some processes show
up with usernames.
Expected Results: All processes should show up with usernames
All processes will show full usernames if I only specify ps -ea --format "%p %u"
As soon as I specify ps -ea --format "%p %u %c", some processes get numeric UIDs
instead of usernames. Also, if I use a ps -eaf, I get some usernames, and some UIDs.
The problem seems to occur per-user. If a user is not translating, it will occur
for most or all of that user's processes.
I think the problem is the length of the username. If the username is longer
than the column, ps prints the uid instead of a truncated username.
What Alexander Larsson has stated is right. I am also facing the same
problem with usernames > 8 chars
The rightward variable stores the value and limits to 8
Suppose i had 9 chars ( as in bhaslinux ) then i added 1 to it
which makes it print things properly
1616 if (fmt->next)
1617 max_rightward = fmt->width + 1;
1619 max_rightward = active_cols - camax + 1;
(please see added '1' to it
Result after this correction
[bhaslinux@bhaslinux ps]$ ./ps -f
UID PID PPID C STIME TTY TIME CMD
bhaslinux 30470 30469 0 11:45 pts/4 00:00:00 bash
bhaslinux 30500 30470 0 11:45 pts/4 00:00:00 ./ps -f
Result before correction ( using /bin/ps )
UID PID PPID C STIME TTY TIME CMD
500 30470 30469 0 11:45 pts/4 00:00:00 bash
500 30501 30470 0 11:45 pts/4 00:00:00 ps -f
The final work to be done will be to either remove the
cols check in the line (omit the (strlen(pp->euser) > max_rightward)
529 if (user_is_number || (strlen(pp->euser) > max_rightward)
which will be a nasty fix
run through the password file and get the max_rightward as the length
of the username with maximum chars
But removing the check will be fine as there are very few people
who will like have extensively long usernames and most of the
organizations prefer to stop with 8 chars.
Bhasker C V
Created attachment 96600 [details]
Patch for output.c file
Apply this patch to procps-2.0.11 output.c
This will truncate the username to 8chars and then display the
username instead of printing the UIDs of the users
Fixed in current release