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. glibc-2.2.4-19.3 ypbind-1.8-1 pam-0.75-19 Version-Release number of selected component (if applicable): procps-2.0.7-11 How reproducible: Sometimes 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 5 [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 39 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.
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
FIX: --------------------------------------------------- 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 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) check like ---- 527 pr_euser(void) 528 { 529 if (user_is_number || (strlen(pp->euser) > max_rightward) which will be a nasty fix OR 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 bhaslinux
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