Episode: 1072
Title: HPR1072: LiTS 015: top part 3 - Control Top
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1072/hpr1072.mp3
Transcribed: 2025-10-17 18:28:43

---

Welcome to Linux in the Shell episode 15, part 3 of top controlling top.
My name is Dan Washco, I will be your host today.
As always, I'd like to thank Hacker Public Radio for hosting the site and the audio
files, so make sure you contribute to Hacker Public Radio or head on over there to listen
to some other great shows.
Today's episode of top, part 3 controlling top, is going to be not the last in this
series of top because there's going to be one more, I believe at least one more, probably
only one more.
But anyway, I remind you to head on over to Linux in the Shell.org to look at the other
two episodes on top if you haven't already, but also to read the full write-up on this
subject and also in the links in the watch the video to solidify top in your mind.
Now the first episode of top, we talked about the summary, top summary area, task summary,
and the second episode, we talked about the task process area, the bottom part of top.
It's this episode, we're going to talk about how to control the general overall display
of top.
So let's jump right in, when you fire up top, you got the top task area is primarily
what you're going to be observing in top of all the tasks, and that's where a lot of
the focus is going to be right now.
When you look at that, it starts off, it's going to show all the processes that are running
on the system.
So you're the list, the task area list, by row, each individual process, by PID, process
ID, and it's going to scroll off the screen.
So there's a whole lot more, probably a whole lot more processes running in your top screen,
but you can't see them.
Well, you can use the arrow keys to navigate down one line at a time through the process
list.
And you can move it up and down, move up and down with the arrow keys, or you can use
the page down to page down one page of items, and page up to page up one item.
You could also use the end key to go to the bottom of the list, and you can use the home
key that will take you back up to the top of the list.
Now if you open up top in a terminal or a console, and you're looking at it full screen
or taking the most of the screen, you'll probably see the default columns, and unless you
have added more columns, they should fit pretty much on your screen.
But if you add more columns, or you're not running it in a full terminal session or console,
you can scroll across the columns using the right and left arrow keys, which will take
you obviously right arrow, take you to the right, scroll to the right, left arrow, scroll
back to the left, and allow you to see the processes that way.
So that's basically what you could do to scroll around that process area.
Now if you wanted to actually search for something specific in that process area, you
can press the capital L key, that shift L, and it'll say, bring up a prompt that says
locate string, and you could type whatever you want in there, and what that will do is
it will case sensitive, of course, because everything in Unix is case sensitive or Linux.
Search for that string on all columns that are displayed.
So if I were to locate string top, it's going to look at all columns where top could possibly
be displayed, and then it should show you your search values that have come up.
Now you can toggle or move through those search values by pressing the amp or sand key,
which will locate the next instance of where the search value was found.
And that's how you can start controlling what you can display in the top window.
Now by default, you can see what top is sorting on.
Because when top is running and it's refreshing, you'll notice things are moving around.
So what is it actually sorting on?
If you press the X key, it's going to highlight the column that's sorting on.
By default, it's this percent CPU usage.
So you'll notice that that column is highlighted.
Now if you wanted to change that what it's actually sorting on, one of the easy ways to do
that is to use the right, the less than key to move to the left, or I'm sorry to the
left because it's pointing to the left, and the greater than key to move to the right.
And that will shift through the columns.
Now if you have the X key, if you have it highlighted, you'll see what columns you're
actually shifting or sorting on as you use the greater than or less than keys.
And of course, that's typically shift, comma, and shift period to get those,
because those keys are right above those symbols are right above those keys.
And it will toggle on and just use that as the sort criteria.
So for instance, in the default, when you're sorting on CPU,
to the right is percent memory.
And if you were to press the greater than key, it would shift it to the right,
and you would be sorting on percent memory from there on and going forward.
There are some hot keys that you can use to sort on specific values.
One is capital M. And if you do that, capital M will sort on memory usage.
Capital N will sort on process ID.
So it will sort on process ID, greater the higher process ID to the bottom.
Now, capital P will sort on CPU.
They say, why isn't PID or process ID capital P?
I don't know. That's just the way it is.
Capital T will sort on time with process has been running the longest to the low.
And then capital R, which is not going to specify what column the sort on,
but it will reverse the sort.
So it will take, instead of going from highest to greatest value to lowest,
it will then go from lowest to highest.
So for instance, if you're sorting on PID process ID, which is capital N,
and by default is going to start with the greatest process ID and sort all the way down
to the lowest, which is typically the init process, which should be the first process.
So if you wanted to, if you were to hit the capital R, it would switch that
and resort from lowest to highest.
So that's what capital R does.
So that's how you can control the sort options in there and look through the task list.
So that's, that's pretty, pretty easy to do right there.
That's your basic controls.
Now, getting a little higher up in some of the basic controls there,
top refreshes itself every three seconds by default.
Now, you can change that by pressing the D key and it's prompt you to say change delay
from three seconds, 3.0.
And remember, this is intense of a second.
So you can specify like 3.5 or 3.5 seconds.
And you can put whatever number you want in there,
one for one second, five for five seconds.
And it will, on the fly, change that value and allow you to.
It'll refresh whatever value that you set right there.
Now, you can also change the refresh value using the ask key.
So S and D change the refresh value.
If you don't enter a value when you bring it up and you're prompted,
it will leave it at whatever the current value is.
Now, you can prompt or, or initiate a refresh automatically by pressing
the space key or the enter key and that will automatically refresh
and restart the count right there.
Now, there is the option and top to toggle on thread mode.
Threads mode is capital H and instead of showing
processes in thread mode and when you're looking at thread mode,
what you're seeing is whether or not processes are shown.
Now, the hot key H capital H that is will turn thread mode on or toggle it.
And you can tell whether you're in threads mode by looking at
up at the top in the summary area.
On the second line, it will say it will show either threads right there or tasks.
When you're in thread mode, it shows each line is a thread and it displays each line in
a task area by threads, whereas in a task mode, it displays it by tasks as opposed to threads.
So you can turn that on and off by using the capital H key.
You can also toggle off on and off Irix mode by using the capital I.
And when you do that, it will tell you when you hit that key right up there in the
the summary area, whether or not Irix mode is on or off, whether you've turned it on or off.
Now, remember, Irix mode is how CPU percentages are calculated.
In Irix mode, if you have one CPU, that's 100%.
If you have two CPUs, it's 200%, three CPUs or four CPUs,
four 100% and so on some percentages are calculated based on that value.
That percentage adds 100% for each CPU, whereas when you turn off Irix mode, it goes into
the hilarious mode. 100% CPU is 100% of all the CPUs.
So one CPU is 100%, two CPUs is 100%, three CPUs is 100%.
So the values that you see for percentages CPU are taking out of whatever mode you're in.
So like 3% in Irix mode is 3% of 400%, whereas in Solaris mode, when you toggle off Irix mode,
3% is 3% of 100%. So we discussed that in the previous episodes.
So if you're still confused about that, check it out.
You can press the capital B key, which will turn bolding on and off, and bolding will
allow you to highlight specific things like the row that you're sorting on will be highlighted,
the current object that you're sorting with will be highlighted or what row you're on or
what row you're actually looking at will be highlighted. So you can turn that bolding highlight
on and off with B. And if you have like row highlight on,
but bold off, it will highlight that whole column there, and it will be a change the background
color of the column, whereas if you have bold on, typically it will also bold it and sometimes
highlight it at the same time. So you get some different values in there. So check it out.
There is an options in top that you can control what processes you see.
For instance, if you wanted to see all the processes by a specific user,
you can press the U key and you can type in like, my name is Dan, I just want to show my processes
and hit Enter. And it will show you all the processes by my user.
If you hit the U key and don't supply any value, it will show all. So you can specify processes by
users with the U key. Now, one thing I want to say if any time you have limited the amount of
processes that you're seeing in the task area and you want to quickly just show everything once
again, you can press the equal key and it will turn off all limited all limitations that you have
specified. So it will return top and remove any restrictions on tasks or anything that you
have set in the display. So it will get you back to showing all the processes. Let's take a step
back a second and let's talk about some switches that you can pass to top. I'm not necessarily
controlling with the hockey and some of these switches that I'm going to talk about. I also do
have hockey's and where they do, I'll really remind you of the hockey or tell you what it is for
the first time. First off, there's cumulative mode. And as I discussed before in the previous episode,
cumulative mode shows the CPU time used by the process since it started and includes the CPU
time consumed by the process is dead children. Okay, so that's what cumulative mode is. It will count
how much time the process has been used or CPU process has taken up since it started plus all
its dead children. By default, that's turned off. Okay, and you can toggle that on and off with
capital S shift S while top is running. But you can start top by passing a dash capital S flag and
it will it will reverse the previous cumulative mode the top is running as. So if your standard
defaults you haven't messed around with anything and you do top dash S, it'll start it in cumulative
mode. Irix mode, which we have talked about so many times now, is on by default and you can pass the
dash i which will toggle it off and put you in Solaris mode by default. Now of course we had said
the hockey for that is shift i or the capital i which will toggle it on the fly. So whatever top
was running out previously the dash i will toggle it and then standard is default is
to Irix mode on so toggle it will turn it off. There's secure mode. Now this mode is there's
only a command line option for this. There's no live option and secure mode is turned on by a dash
S. Okay, and what secure mode does is it disables some of the functionality of top and that functionality
would be like being able to kill a process or re-nice a process or some of the things and secure
mode that you won't allow it to do. It will even restrict the root user from doing those if you
run top is root user and pass it to dash S. In fact, if you're going to run top as the root user,
you should probably go with the dash S especially if you're going to leave it up for a long time
and somebody else might have access to the system. You don't want them willingly killing processes
by accident or re-nicing them. So secure mode can only be turned on by a command line switch.
We talked about threads mode which is a capital H. We'll toggle it on or off. Default is it's off
and it shows tasks as opposed to thread but a capital H will turn thread modes on when you
start top and display threads instead of tasks. Now with cumulative mode Irix mode and threads
you can switch the toggling of those using the hot keys that we discuss so you can change those on
the fly. By default top is going to show all the processes that you have that are going along
on the system so it will not discriminate but you can tell it to only show specific process ideas
with the dash P switch from the command line and you can specify more than one process idea up to 20
with a dash P one process ID and you can you can do it one of two ways is either dash P for each
process ID so it would be like dash P 779 space dash P 8510 and so on up to 20 or you can do dash P
and then process 779 comma 8510 comma and so on display them with a comma separated list.
And when you do that it'll show you only those processes. Now if you want to get out of that mode
okay you can press the equal key like I had said before and it will take you out of that
restricted mode and show you all the processes. Like process ID you can limit the display of
processes by real user I mean effective user or all users by using the dash you or the dash
capital U key parameter pass to it. Now you can only pass one user to it and dash U is specifically
effective user so that's what the process is currently running as. So for instance if I do top
space dash U Dan it will show only top only show all the processes that are running as me
under my user account. Now remember effective user also includes processes that were altered when
they ran like they're now running under SUID so if I ran a process that SUID to root it would
show effective user and would not necessarily show that process under my name it was showed under
root whereas if you pass the dash capital U it's going to show all the processes that that are
running or running as a different user from that person also. Now of course once you have
that restriction put in there you don't have to quit top and restart it to show all processes
just hit the equal key and it will take you back to what you were running before. Top has a width
to it okay so width of columns and it runs from one column up to 512 columns and if you really
wanted to limit how many columns are displayed in top on the screen you can pass the W command
dash W and restrict the number of columns by specifying the number from one to 512. Top runs
continuously and it has the refresh intervals which are specified by the dash D. Now top has a
mode that you can specify it to run for a set number of intervals. I had mentioned this in a
previous show and that was with the dash N so you can do top space dash N and some number like
one to whatever say five and it would run for five intervals so it would start up
be one is the first interval and then run for four more refreshes and quit and that would be it
that's useful for going for passing to top to run it in batch mode which is a dash B.
Batch mode will run top for a set number of intervals and if you don't pass the intervals
it will continuously it'll keep running but batch mode is useful for when you want to take the
output of top and pipe it to a file or you want to pipe it to another program or another program
batch mode will start top up and it won't accept any input so if you pass the dash N to it it will
run for a set number of intervals and batch mode doesn't accept any input or controls and then
quits that's all it does if you don't run it with a set number of intervals it will keep running
continuously and you'd have to quit it with control C so that's batch mode useful if you're
running top to get information into another application or a file top has a forest view mode and
if you can pass it the forest view mode with this hot key so if you're starting top you want to see
like a tree mode you would pass you would pass capital V and what that'll do is it will show you
like the top process and then each process that's running underneath it in a tree fashion so
for instance i'm looking at top right now and it's running the first process is running as in it
and underneath it i see all the the processes that it has spawned that are running underneath it
in a tree like mode so that can be handy if you want to see what what process is a parent of another
process and you can of course toggle threads mode on and off to look at them in tree mode but it
could be handy you you toggle tree mode with the capital vk so it shows a hierarchical tree
ordered by their parent and that can be pretty handy so all in all oh i don't want to stop here
there's there's a few control things you for controlling processes in top now remember these
are turned off by default insecure mode that didn't make any sense because secure mode isn't
default but these are turned off in secure mode so you can't use these in secure mode but the
two we're going to talk about is killing a process and re-nicing a process now you can kill a
process by pressing the k key and it'll ask you for the PID to kill and you would put in the PID
number and then it's going to ask you what send what PID signal PID 16 signal so 0 to 16
for 0 to 15 typically you're going to pass it to the one which is a hang up or nine which is a kill
and you can press you type in nine and then it will kill that process if you have permission to
do that if you are running as a normal user and you try to kill a root process it's not going to
happen if you're running in secure mode you try and kill a process even as root it will tell you
that it's restricted it's in secure mode you can't do it then there's re-nice process which is
or you could press the R key to re-nice process and it does the same thing it says okay what
PID you want me to re-nice and you press the PID and you and it says would you want the value to be
right it's a value from a negative 19 to 19 where the lower the number the higher the priority is
given so highest priority is given the negative 19 lowest priority is given the 19 so if you try and
pass re-nice to a process that you don't control it will tell you that the operation is not permitted
if you try to re-nice a process that you do control but you're not root and you try to re-nice
anything greater than negative 10 I'm sorry lower than negative 10 in this case which increases
the priority it will tell you that the operation not permitted so a standard user you can re-nice a
process that you control from negative 10 to 19 whereas root user if you're in there as a
root user you can re-nice it to negative 19 if you want to so standard user negative 10 to 19
root user negative 19 to 19 now if you pass a value greater than 19 like 25 35 45 it's just
going to re-nice it to 19 it won't complain or most of the time it won't complain to you but it's
not going to do it anything higher than 19 that is the basics of controlling top right there I
think I pretty much covered everything really the basics there more information you can always
hit the h key which takes you to the help screen and that gives you some of the options that we
have talked about in there and in the previous episodes for toggling things on and off from
moving around on the screen the last thing I'll say is don't forget controlling what fields
are displayed on the screen by getting into the fields mode fields management mode by pressing the
f key and that'll control the toggles what we're going to talk about next time our task windows
alternate windows and displays and color highlighting syntax and stuff like that so that's
where we're going to end here is just controlling the output of what you see in top and the final
episode which I hope will be the final episode we'll be talking about alternate window displays
and highlighting in different colors schemes that you can do in top my name is damn washgo this has
been Linux in the shell supported by hacker public radio head on over to the website look at for
episode 15 to do the full read up on this and to also watch the video as a note if you had watched
the video last week or last two weeks ago on the second episode there was a zombie process listed
and I did not know what that zombie process was it's a time well I found out what that zombie
process was it was the GTK record my screen spawns a process bunch of processes to take screenshots
and stuff that is what the zombie process was from was that right there so pretty cool check out the
website check out the videos and we'll be back here for the final installment hopefully final
installment of top in two weeks have a great day
you have been listening to Hacker Public Radio at Hacker Public Radio does our we are a community
podcast network the releases shows every weekday on day through Friday today's show like all our
shows was contributed by an HPR listener like yourself if you ever consider recording a podcast
then visit our website to find out how easy it really is Hacker Public Radio was founded by the
digital dot-pound and the infonomicum computer club HPR is funded by the binary revolution
at binref.com all binref projects are crowd sponsored by linear pages from shared hosting to
custom private clouds go to lunar pages.com for all your hosting needs unless otherwise stasis
today's show is released under a creative comments attribution share a like
details are licensed
