11

On our systems user names can be up to 20 characters long. But the top commands only displays the first 8 characters.

How can I configure top to display the whole user name?

At the moment we use: top procps version 3.2.8 (linux)

But a different top implementation could be installed.

The oldest system we need to support is this:

Linux foohost 2.6.37.1-1.2-desktop #1 SMP PREEMPT 2011-02-21 10:34:10 +0100 x86_64 x86_64 x86_64 GNU/Linux
2
  • 1
    What platform are you on? Use uname -a
    – Kevdog777
    Commented Dec 13, 2013 at 9:23
  • 1
    @Kevdog777 I updated the question, and added uname -a
    – guettli
    Commented Dec 13, 2013 at 11:36

4 Answers 4

8

Can't really help you with older 3.2.x versions of procps but in newer ones (e.g. definitely 3.3.10 and I think it went back to 3.3.4) you can adjust the size of fixed columns. The key you are looking for is capital X.

To use this feature, first start top. Ideally, but not essential, you will "make room" for your column by either removing other columns or expanding your terminal. Use f to bring up your field list and deselect what you don't need. Once you are happy with field selection, hit q to get back to the process list.

Then use X command which asks you for how much to increase the width, generally -1 works ok. You might get this strange "column growing" effect but after a few refeshes you can see the full username.

  PID USER          PR    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND     
 3775 libvirt-qemu  20 4667404 960508  14724 S   6.1  5.9 188:04.01 qemu-syste+ 
 3825 Debian-gdm    20 1516152 114924  64404 S   2.7  0.7   1:52.09 gnome-shell 

Notice that the command name is now truncated (ends with a +) because our username is longer and has pushed the other columns to the right. Whether or not you think this a a good idea depends what you are looking for.

8

Looking at the sources of top, it seems that there's a hardcoded maximum of 8 chars:

1223    static FLD_t Fieldstab[] = {
1229          keys   head           fmts     width   scale  sort   desc                     lflg
1230         ------  -----------    -------  ------  -----  -----  ----------------------   -------- */
1235       { "EeDd", " USER    ",   " %-8.8s",  -1,    -1, SF(URE), "User Name",            L_EUSER  },

The fmts colum is a printf format string. %-8.8s means left padded string of minimum and maximum size of 8.

2

It looks like there is currently no way to do this as you request with terminal programs. What you ask is not new and actually is on htop feature request list, but it has been that way for a year and a half and no milestone has been set to implement this yet. No sign of that at all for top. 2 options could be:

1) Two terminals

You can tell top (e.g. you can use f as it runs) to show the UID not the name. If you have split your terminal in 2 fields such as with terminator or screen then you can run top in the upper larger screen and query for the username in the lower e.g.

awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd

substituting whatever UID you want to look at for 1000. Of course, you could wrap it in a very small bash script so you should only type a few letters of your script name and the UID. Also if you are talking about non local users you can use getent passwd as input for awk instead of /etc/passwd file - like so:

getent passwd | awk -v val=1000 -F ":" '$3==val{print $1}'

2) ps option

You could use ps to give you 15 most CPU heavy processes and who they belong to. You can vary the number of processes of course.

ps -ef | egrep -v "STIME|$LOGNAME" | sort -k4 -r | head -n 15 | colrm 100

Explanation:

ps -ef                     gives you all processes 
egrep -v "STIME|$LOGNAME"  removes the header line
sort -k4 -r                sorts by the CPU column in reverse (biggest on top)
head -n 15                 gives you first 15 lines of above
colrm 100                  restricts each line of output to 100 characters 

The last command is useful as some programs sch as google chrome have very long options lines after the command, so your output will be difficult to read if you don't cut the lines.

1

Use htop instead, which shows longer usernames.

htop Manual page

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .