Bug 88981 - "ps" does not consistently translate UIDs to usernames against NIS users
"ps" does not consistently translate UIDs to usernames against NIS users
Product: Red Hat Linux
Classification: Retired
Component: procps (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Daniel Walsh
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2003-04-15 19:05 EDT by Ross Becker
Modified: 2007-04-18 12:53 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-02-11 08:25:55 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Patch for output.c file (1.02 KB, patch)
2003-12-18 06:16 EST, Bhaslinux
no flags Details | Diff

  None (edit)
Description Ross Becker 2003-04-15 19:05:22 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2)
Gecko/20030208 Netscape/7.02

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
interacting here. 

Here are some of the other software versions which might be interacting with the
"ps" command.

Version-Release number of selected component (if applicable):

How reproducible:

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
rhalbhavi:*********:2193:2004:Raj Halbhavi:/home/rhalbhavi:/bin/csh
[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

Additional info:

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.
Comment 1 Alexander Larsson 2003-04-16 06:05:37 EDT
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.

Comment 2 Bhaslinux 2003-12-17 05:40:15 EST
What Alexander Larsson has stated is right. I am also facing the same 
problem with usernames > 8 chars 
Comment 3 Bhaslinux 2003-12-18 01:18:37 EST

File: output.c 

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;
1618                 else
1619                         max_rightward = active_cols - camax + 1;

(please see added '1' to it 

Result after this correction
[bhaslinux@bhaslinux ps]$ ./ps -f
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 ) 
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)
check like 
527 pr_euser(void)
528 {
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
Comment 4 Bhaslinux 2003-12-18 06:16:50 EST
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
Comment 5 Daniel Walsh 2004-02-11 08:25:55 EST
Fixed in current release

Note You need to log in before you can comment on or make changes to this bug.