Discussion:
Question: Reading the Output of Top
Parham Doustdar
2016-05-06 06:59:40 UTC
Permalink
Hi all,

What do you do when you want to read content of a command like |top|?
There are two issues with it:

1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.

How do you get through these issues?

Thanks!


John G Heim
2016-05-06 13:30:17 UTC
Permalink
I doubt that there is an answer to your first question. You could
probably write a script to do it.

As for your second question, I run top thusly, 'top -bn1 | more'. This
runs top in batch mode and has it retrieve the data just once. Piping
the output to more keeps the data from scrolling off the top. What you
get is a snapshot of the data at the moment you run the top command.

PS: You can also set the refresh rate for top to something high enough
for you to listen to the output.
Post by Parham Doustdar
Hi all,
What do you do when you want to read content of a command like |top|?
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
How do you get through these issues?
Thanks!

_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
--
--
John G. Heim; ***@math.wisc.edu; sip://***@sip.linphone.org
Parham Doustdar
2016-05-07 11:24:34 UTC
Permalink
Hi John,

I doubt that there is an answer to your first question. You could
probably write a script to do it.

Top is unusable without such a feature, but you and other people
replying to this thread seem to be using it just fine. So, what tricks
do people use in order to memorize what column is for what value? I have
this problem when reading the output of commands like |free -m|, too.

Thanks!
Post by John G Heim
I doubt that there is an answer to your first question. You could
probably write a script to do it.
As for your second question, I run top thusly, 'top -bn1 | more'. This
runs top in batch mode and has it retrieve the data just once. Piping
the output to more keeps the data from scrolling off the top. What you
get is a snapshot of the data at the moment you run the top command.
PS: You can also set the refresh rate for top to something high enough
for you to listen to the output.
Post by Parham Doustdar
Hi all,
What do you do when you want to read content of a command like |top|?
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
How do you get through these issues?
Thanks!

_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup

Tony Baechler
2016-05-07 11:38:33 UTC
Permalink
Top is unusable without such a feature, but you and other people replying to
this thread seem to be using it just fine. So, what tricks do people use in
order to memorize what column is for what value? I have this problem when
reading the output of commands like |free -m|, too.
Well, I just listen very carefully. I've not had a problem with it, but I
see what you mean with top in particular. It's hard to know what's going on
when you hear a bunch of numbers scrolling past. That's why I suggested
parking the cursor, but that doesn't stop the output. I would suggest "top
-n1" to only show the information once or increase the refresh rate as John
suggests.

Regarding free memory, I cheat. You can actually do this with top and most
other commands. In Linux, there is a special filesystem called /proc. It's
worth exploring some time as you can learn lots of useful information. All
top, ps, free and lots of other commands do is reformat the output of files
under /proc to make them look nicer. I don't know what files top uses, but
read the man page. For fun, try the following two commands and let us know
what you think:

cat /proc/meminfo
less /proc/cpuinfo

You can do the same with the ps command. All ps does on Linux is go through
/proc and print out the process names, memory and CPU usage, etc. I find ps
more useful and easier though, especially when there are hundreds of running
processes on most servers.
Willem van der Walt
2016-05-07 11:51:44 UTC
Permalink
I usually just want to know how busy the machine is, so then I use uptime.
To check if the machine is swapping, I just use the free command.
HTH, Willem
Post by Tony Baechler
Top is unusable without such a feature, but you and other people replying
to
this thread seem to be using it just fine. So, what tricks do people use in
order to memorize what column is for what value? I have this problem when
reading the output of commands like |free -m|, too.
Well, I just listen very carefully. I've not had a problem with it, but I
see what you mean with top in particular. It's hard to know what's going on
when you hear a bunch of numbers scrolling past. That's why I suggested
parking the cursor, but that doesn't stop the output. I would suggest "top
-n1" to only show the information once or increase the refresh rate as John
suggests.
Regarding free memory, I cheat. You can actually do this with top and most
other commands. In Linux, there is a special filesystem called /proc. It's
worth exploring some time as you can learn lots of useful information. All
top, ps, free and lots of other commands do is reformat the output of files
under /proc to make them look nicer. I don't know what files top uses, but
read the man page. For fun, try the following two commands and let us know
cat /proc/meminfo
less /proc/cpuinfo
You can do the same with the ps command. All ps does on Linux is go through
/proc and print out the process names, memory and CPU usage, etc. I find ps
more useful and easier though, especially when there are hundreds of running
processes on most servers.
_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
--
This message is subject to the CSIR's copyright terms and conditions, e-mail
legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at
http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by
MailScanner,
and is believed to be clean.
Please consider the environment before printing this email.
John G. Heim
2016-05-07 15:57:09 UTC
Permalink
The 2 main tools I use for overcoming challenges like this are hard work
and determination.

But over this weekend, I think I'll try to find a few hours to put
together some perl code to linearize output from a command line program.
Perl is good for parsing output. I could use the perl module for taking
single key input. I don't even remember what it's called, it's been so
long since I used it. First draft would just break the columns down and
allow you to move around the cells. Down arrow goes down a row. Left
arro goes left. Etc. I could really use a program like that myself. As
bad as top is to listen to, try listening to the output from sar.
Post by Parham Doustdar
Hi John,
I doubt that there is an answer to your first question. You could
probably write a script to do it.
Top is unusable without such a feature, but you and other people
replying to this thread seem to be using it just fine. So, what tricks
do people use in order to memorize what column is for what value? I
have this problem when reading the output of commands like |free -m|, too.
Thanks!
Post by John G Heim
I doubt that there is an answer to your first question. You could
probably write a script to do it.
As for your second question, I run top thusly, 'top -bn1 | more'.
This runs top in batch mode and has it retrieve the data just once.
Piping the output to more keeps the data from scrolling off the top.
What you get is a snapshot of the data at the moment you run the top
command.
PS: You can also set the refresh rate for top to something high
enough for you to listen to the output.
Post by Parham Doustdar
Hi all,
What do you do when you want to read content of a command like
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
How do you get through these issues?
Thanks!

_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup

John G. Heim
2016-05-07 18:47:28 UTC
Permalink
Okay, I threw together a script to linearize table output from programs
like top. It's at:
http://www.math.wisc.edu/~jheim/pub/linearize

You can get it with wget:

$ wget http://www.math.wisc.edu/~jheim/pub/linearize

To run it, type linearize and your command after it. For example, to use
it with top, do this:

linearize top -bn1

The keys you have to use are configured at the top of the script. I had
to choose keys that would not interfere with speakup or orca so I picked
i to move up a line, the comma to move down a line, j to move left a
cell, and l to move right a cell. They form a little cross on the
keyboard. But you can easily change them to whatever you like by editing
the script. Let me know if you think there is a more logical set of keys
that don't interfere with other functions.

One tricky thing. There is a key defined to set the column headings.
Press the h key and the script will use the current line for column
headings. Behaviour of the left and right keys is undefined until you do
this. So if you are using the script with top, you'd want to use the
comma to move down several times until you hear the first line of the
table listing processes. Then press the h key. From then on you can move
around as if you are in a table.
Post by Parham Doustdar
Hi John,
I doubt that there is an answer to your first question. You could
probably write a script to do it.
Top is unusable without such a feature, but you and other people
replying to this thread seem to be using it just fine. So, what tricks
do people use in order to memorize what column is for what value? I
have this problem when reading the output of commands like |free -m|, too.
Thanks!
Post by John G Heim
I doubt that there is an answer to your first question. You could
probably write a script to do it.
As for your second question, I run top thusly, 'top -bn1 | more'.
This runs top in batch mode and has it retrieve the data just once.
Piping the output to more keeps the data from scrolling off the top.
What you get is a snapshot of the data at the moment you run the top
command.
PS: You can also set the refresh rate for top to something high
enough for you to listen to the output.
Post by Parham Doustdar
Hi all,
What do you do when you want to read content of a command like
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
How do you get through these issues?
Thanks!

_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup

Willem van der Walt
2016-05-12 05:31:16 UTC
Permalink
Hi John,
Thanks for this. I am about to try it now.
Regards, Willem
Post by John G. Heim
Okay, I threw together a script to linearize table output from programs
http://www.math.wisc.edu/~jheim/pub/linearize
$ wget http://www.math.wisc.edu/~jheim/pub/linearize
To run it, type linearize and your command after it. For example, to use
linearize top -bn1
The keys you have to use are configured at the top of the script. I had
to choose keys that would not interfere with speakup or orca so I picked
i to move up a line, the comma to move down a line, j to move left a
cell, and l to move right a cell. They form a little cross on the
keyboard. But you can easily change them to whatever you like by editing
the script. Let me know if you think there is a more logical set of keys
that don't interfere with other functions.
One tricky thing. There is a key defined to set the column headings.
Press the h key and the script will use the current line for column
headings. Behaviour of the left and right keys is undefined until you do
this. So if you are using the script with top, you'd want to use the
comma to move down several times until you hear the first line of the
table listing processes. Then press the h key. From then on you can move
around as if you are in a table.
Post by Parham Doustdar
Hi John,
I doubt that there is an answer to your first question. You could
probably write a script to do it.
Top is unusable without such a feature, but you and other people
replying to this thread seem to be using it just fine. So, what tricks
do people use in order to memorize what column is for what value? I
have this problem when reading the output of commands like |free -m|, too.
Thanks!
Post by John G Heim
I doubt that there is an answer to your first question. You could
probably write a script to do it.
As for your second question, I run top thusly, 'top -bn1 | more'.
This runs top in batch mode and has it retrieve the data just once.
Piping the output to more keeps the data from scrolling off the top.
What you get is a snapshot of the data at the moment you run the top
command.
PS: You can also set the refresh rate for top to something high
enough for you to listen to the output.
Post by Parham Doustdar
Hi all,
What do you do when you want to read content of a command like
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
How do you get through these issues?
Thanks!
_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
--
This message is subject to the CSIR's copyright terms and conditions, e-mail
legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at
http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by
MailScanner,
and is believed to be clean.
Please consider the environment before printing this email.
Janina Sajka
2016-05-13 14:38:19 UTC
Permalink
The observation that the data provided by top is directly available in
the /proc file system tree is actually very useful, because you can
simply write a script or two to query for common concerns.

I have a script, which I alias to a command called lav, for checking the
current system load average in a running, real time report:

<begin script>
while true; do cat /proc/loadavg |cut -b 1-5; sleep 5; done
<end script>

Just Ctrl+C to stop.

I have a variant, this time written as a simple bash script, that also
uses the ps command to report the process which top would report as the
heaviest resource consumer like so:

<begin script>
#!/bin/bash
while true; do
cat /proc/loadavg |cut -b 1-5
sleep .5
#Sort pids to greatest consumer
for APP in $(ps -e --sort %cpu |cut -b 17-); do
echo $APP >/dev/null
done
echo $APP
sleep 4
done
<end script>

The above works on Fedora 23 for me right now. Note that your distro may
do things a bit differently, but the data is most certainly going to be
available if you look in the write place.

The value of checking for the top cpu hog is that load averages are
often the result of a process gone out of control somehow. I simply kill
the offender, and 99% of the time my machine returns to a sane state.
That's why I've found having this data directly available in a script
useful, it takes less time to get at than listening to the complete
output of top, or even faster than hitting ScrollLock on top and finding
the top cpu hog manually.

hth

Janina
Post by Parham Doustdar
Hi John,
Thanks for this. I am about to try it now.
Regards, Willem
Post by John G. Heim
Okay, I threw together a script to linearize table output from programs
http://www.math.wisc.edu/~jheim/pub/linearize
$ wget http://www.math.wisc.edu/~jheim/pub/linearize
To run it, type linearize and your command after it. For example, to use
linearize top -bn1
The keys you have to use are configured at the top of the script. I had to
choose keys that would not interfere with speakup or orca so I picked i to
move up a line, the comma to move down a line, j to move left a cell, and
l to move right a cell. They form a little cross on the keyboard. But you
can easily change them to whatever you like by editing the script. Let me
know if you think there is a more logical set of keys that don't interfere
with other functions.
One tricky thing. There is a key defined to set the column headings. Press
the h key and the script will use the current line for column headings.
Behaviour of the left and right keys is undefined until you do this. So if
you are using the script with top, you'd want to use the comma to move
down several times until you hear the first line of the table listing
processes. Then press the h key. From then on you can move around as if
you are in a table.
Post by Parham Doustdar
Hi John,
I doubt that there is an answer to your first question. You could
probably write a script to do it.
Top is unusable without such a feature, but you and other people
replying to this thread seem to be using it just fine. So, what tricks
do people use in order to memorize what column is for what value? I have
this problem when reading the output of commands like |free -m|, too.
Thanks!
Post by John G Heim
I doubt that there is an answer to your first question. You could
probably write a script to do it.
As for your second question, I run top thusly, 'top -bn1 | more'. This
runs top in batch mode and has it retrieve the data just once. Piping
the output to more keeps the data from scrolling off the top. What you
get is a snapshot of the data at the moment you run the top command.
PS: You can also set the refresh rate for top to something high enough
for you to listen to the output.
Post by Parham Doustdar
Hi all,
What do you do when you want to read content of a command like
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
How do you get through these issues?
Thanks!
_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
--
This message is subject to the CSIR's copyright terms and conditions,
e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at
http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
Please consider the environment before printing this email.
_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
--
Janina Sajka, Phone: +1.443.300.2200
sip:***@asterisk.rednote.net
Email: ***@rednote.net

Linux Foundation Fellow
Executive Chair, Accessibility Workgroup: http://a11y.org

The World Wide Web Consortium (W3C), Web Accessibility Initiative (WAI)
Chair, Accessible Platform Architectures http://www.w3.org/wai/apa
Tony Baechler
2016-05-06 10:06:46 UTC
Permalink
Post by Parham Doustdar
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
I'm sure others have good answers, but I haven't found a good solution. You
can park the Speakup cursor and you can change the frequency output is
updated, like every 20 seconds. You can use the review keys to read the
column headers. I think there is a way to get more verbose output without
the columns, but you'd have to read the man page.
Post by Parham Doustdar
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
Try this very helpful command:

top -n1 | head
Jude DaShiell
2016-05-07 11:15:25 UTC
Permalink
It may also help to run top with screen as perhaps a first command then
open up additional screens to perform other work and have the first
screen with top running on it backgrounded while this is going on.
Date: Fri, 6 May 2016 06:06:46
Reply-To: Speakup is a screen review system for Linux.
Subject: Re: Question: Reading the Output of Top
Post by Parham Doustdar
1. There is no way of knowing the title of a column without first
navigating to the headers. I want to be able to go to the
next/previous column, know the title of a column, etc.
I'm sure others have good answers, but I haven't found a good solution. You
can park the Speakup cursor and you can change the frequency output is
updated, like every 20 seconds. You can use the review keys to read the
column headers. I think there is a way to get more verbose output without
the columns, but you'd have to read the man page.
Post by Parham Doustdar
2. The output keeps changing. For example, while I???m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
top -n1 | head
_______________________________________________
Speakup mailing list
http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup
--
Jason White
2016-05-14 15:50:10 UTC
Permalink
Post by Parham Doustdar
2. The output keeps changing. For example, while I’m reading one line,
its CPU usage might drop and cause it to be reordered in the list.
top -b -n1|less
will at least give you output that can more easily be reviewed, and which
won't change while you're reading it.

This doesn't meet all of your requirements, but it may help to some extent.

You can obviously change the parameter to the -n option to modify the number
of samples taken.

Loading...