Linux ps's problem with login names

August 8, 2012

I generally like the usual Linux verions of various utilities, GNUisms and all; at least they work reliably under many circumstances. The Linux version of ps is not one of those programs. Unfortunately, for reasons that I believe are at least partly political, Linux ps is a mess; as one example, the major distributions have had to fork procps (and the original main code hasn't seen a release for several years).

One irritating example of this mess is how ps treats login names, specifically how it treats long login names. To put it simply, unless you go to a lot of work ps prints all login names that are longer than eight characters as numeric UIDs. This is what you'd call a problematic limitation because Linux distributions have been using long login names for system accounts for years and running daemons as some of those accounts. In other words this limitation triggers all the time on modern Linux systems when you're looking at all processes (as sysadmins do with reasonable frequency), even if you don't have any users with long login names. (If you do, well, things are worse.)

In a sane world ps would have a simple command line switch to override this behavior. In this world ps has almost every option under the sun but this one (as you can see if you browse the manual page); as far as I know, you will search in vain among all of the options for 'long' and 'full' output and so on. The only way to change this is to resort to specifying a custom output format with a magic modifier on the login name field.

(Just as irritating is where the limitation and workaround are documented. The general existence of the limitation is mentioned in a single sentence at the end of the NOTES section of the manpage. How to work around it is sort of covered in the writeup of the -o option, which discusses how to widen fields. The actual size limit for login names is not covered anywhere; you have to intuit it from knowing that login names traditionally had to be eight characters or less.)

Sidebar: An example of how to work around this

Taken from a script I have that uses ps:

ps -A -o user:17= -o pid= -o ppid= -o tty= -o args=

This shows how to combine omitting column headers with force-widening the field. Change 17 to some number that makes you happy.

If you want to see how long your login names are:

cut -d: -f1 /etc/passwd | awk 'length($1) > 8 {print length($1), $1}' | sort -nr

On some of our Ubuntu 12.04 machines (installed with Gnome stuff), the longest system login names are speech-dispatcher, avahi-autoipd, Debian-exim, and messagebus. The latter two are used by common daemons (Exim and dbus-daemon); I don't know if the first two are or if they're just used to own files.

Written on 08 August 2012.
« The theoretical legality of shadowing builtins in Python
Ubuntu 12.04 and symbolic links in world-writeable sticky-bitted directories »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Aug 8 01:50:12 2012
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.