Unfortunately the default ps does not display a username if the username is longer than 8 chars. If your system is running sssd with LDAP you can use "getent passwd userid" to find the user if they are in the LDAP database or the password file. My username "tvb" almost always shows up. However the username "flonglastname" would not in most cases. Other commands like "w" will show the first 8 chars "flonglas" and truncate the remaining. In the example by @KevinO above, "haldaemon" is 9 chars so that's why it doesn't appear in ps as a username, but a userid instead.
% getent passwd haldaemon
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
Also, the answer at blog.dbi-services.com helps with a way to specify the field length of the username field even in BSD format ps output. Simplifying their suggestion a little gives:
env PS_FORMAT='user:12,pid,%cpu,%mem,vsz,rss,tty,stat,start,time,command' ps ax | grep haldaemon
haldaemon 2032 0.0 0.0 53100 2020 ? Ssl Aug 12 00:01:10 hald
Which provides the desired output.
getent passwd 506
andgetent passwd $username
work? (I thinkgetent
should lookup by number on CentOS) – ilkkachu Jun 06 '17 at 14:19