ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Using Top

    IT Discussion
    sam linux administration sam linux desktop administration top scott alan miller article linux centos fedora ubuntu opensuse memory process monitoring
    4
    20
    4.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      No Linux utility is more well known than the venerable top command. While many people have moved on from top to more modern tools such as htop and glances, top is still the main "go to" tool for instananeous system monitoring as it is light and widely available on essentially any Linux installation. All major distributions have it in their repos and essentially all install it by default. It is the one tool of this nature that, with relative confidence, you can be sure will be available to you at all times.

      Using top shows a lot of information, here is an example standard output from a Fedora system:

      0_1498941274914_Screenshot from 2017-07-01 15-34-24.png

      As you can see, we have a lot of data at which to look, even by default. This display updates ever 1.5 seconds by default. nearly everything in top can be configured, but most people stick to just a few basic use cases. To learn more about top, just use the "man top" command in your distribution to read the extensive users manual.

      The header section gives us a system summary including the system time, uptime and load factor averages. This is the same load information that we get from the uptime command.

      We also see tasks, which shows us general process statistics including how many we have, and what states they are currently in. The total number of tasks should mirror the number if the ps aux command. This is the source of that data (or they share a source in /proc.)

      The CPU line shows us the current CPU activity in a standard way.

      The Memory and Swap lines show us basic memory statistics in real time, as well. This does not have data pulled out for us like free does, so this takes a little more effort to read. See the free page in this guide for a better understanding of how free handles this data.

      The real meat of the top command is in the process list. This, by default, is sorted by the amount of CPU time used during the monitoring period. A quick look at this chart shows us:

      PID: The Process ID of the process (task) in question.
      USER: The system user that owns the process.
      PR: The priority of the process.
      NI: The nice value of the process.
      VIRT: The virtual memory size of the process.
      RES: The resident set size of the process.
      ** SHR**: The shared memory size of the process.
      S: The process state with S for sleeping, R for running, Z for zombie.
      %CPU: The percentage of the CPU used by the process (by default, this is the sort order of the list.)
      %MEM: The percentage of all memory used by the process.
      TIME+: The total accumulated processor time used by the process since being spawned.
      COMMAND: The command that spawned the process initially.

      Processes which are currently running (the S field is an R) are highlighted.

      With this information, top tells us a lot about what is going on on our system. There are two really common options that make top even more powerful.

      Sort by Memory Usage: Press "M" while top is running and the process list will immediately resort by the %MEM field instead of by the %CPU field. This can be really helpful in identifying processes hogging memory. Press "P" to return to the default view.

      Show CPUs Individually: Press "1" while top is running to toggle between viewing all thread processors (labelled as CPU) aggregated in a single line in the header to having each logical thread processor broken out to show individual activity. This can be extremely helpful in identifying if a process is capped because it has exhausted a single thread capacity while the system as a whole may be mostly idle. When toggled to viewing each logical thread processor individually the %CPU field switches from displaying the number as a percentage of the whole to display the percentage of a single thread processor. So what might be using 5% of CPU in a eight LTP system, will show as 40% when this mode is toggled on.

      Here is the stock view with all LTPs aggregated into one line:

      top header

      And here it is with them broken out:

      top header expanded

      You exit the top command by hitting "q" to quit.


      You can explore many additional options in top that you may find useful. It is an extensive monitoring system. For example, you can, with "m" toggle between different memory views:

      0_1498947041930_Screenshot from 2017-07-01 17-09-45.png
      0_1498947048669_Screenshot from 2017-07-01 17-10-04.png
      0_1498947052969_Screenshot from 2017-07-01 17-10-16.png

      Or you can use "T" to sort the chart by total CPU time.


      Part of a series on Linux Systems Administration by Scott Alan Miller

      BRRABillB 1 Reply Last reply Reply Quote 6
      • dbeatoD
        dbeato
        last edited by

        Admittedly I use more htop than top. Top has saved me many times ahen the system cannot connect to the Internet and troubleshooting. I also use ps aux as well to narrow down my searches.

        1 Reply Last reply Reply Quote 2
        • BRRABillB
          BRRABill @scottalanmiller
          last edited by

          @scottalanmiller said

          Sort by Memory Usage: Press "M" while top is running and the process list will immediately resort by the %MEM field instead of by the %CPU field. This can be really helpful in identifying processes hogging memory. Press "P" to return to the default view.

          That's a capital "M" for anyone still getting used to the fact that capitalization truly matters in Linux.

          Though "m" does something interesting as well.

          scottalanmillerS 1 Reply Last reply Reply Quote 1
          • scottalanmillerS
            scottalanmiller @BRRABill
            last edited by

            @BRRABill said in Linux: Using Top:

            @scottalanmiller said

            Sort by Memory Usage: Press "M" while top is running and the process list will immediately resort by the %MEM field instead of by the %CPU field. This can be really helpful in identifying processes hogging memory. Press "P" to return to the default view.

            That's a capital "M" for anyone still getting used to the fact that capitalization truly matters in Linux.

            Though "m" does something interesting as well.

            Linux isn't what actually cares. It's the filesystem that is case sensitive, not the OS. And in the case of top we are talking about an application and Windows applications are case sensitive just the same.

            BRRABillB 1 Reply Last reply Reply Quote 0
            • BRRABillB
              BRRABill @scottalanmiller
              last edited by

              @scottalanmiller said

              Linux isn't what actually cares. It's the filesystem that is case sensitive, not the OS. And in the case of top we are talking about an application and Windows applications are case sensitive just the same.

              Oh so Windows users should be just as used to dealing with capitalization mattering?

              scottalanmillerS 1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller @BRRABill
                last edited by

                @BRRABill said in Linux: Using Top:

                @scottalanmiller said

                Linux isn't what actually cares. It's the filesystem that is case sensitive, not the OS. And in the case of top we are talking about an application and Windows applications are case sensitive just the same.

                Oh so Windows users should be just as used to dealing with capitalization mattering?

                Of course. Capitalization has always mattered. It's specific cases like the filesystem and SMB protocol where they strip it out. But everything else uses it... from URLs to applications to anything mounted on NFS, etc.

                JaredBuschJ 1 Reply Last reply Reply Quote 1
                • JaredBuschJ
                  JaredBusch @scottalanmiller
                  last edited by

                  @scottalanmiller said in Linux: Using Top:

                  @BRRABill said in Linux: Using Top:

                  @scottalanmiller said

                  Linux isn't what actually cares. It's the filesystem that is case sensitive, not the OS. And in the case of top we are talking about an application and Windows applications are case sensitive just the same.

                  Oh so Windows users should be just as used to dealing with capitalization mattering?

                  Of course. Capitalization has always mattered. It's specific cases like the filesystem and SMB protocol where they strip it out. But everything else uses it... from URLs to applications to anything mounted on NFS, etc.

                  Even IIS cares, just by default they setting was enabled to ignore case sensitivity

                  1 Reply Last reply Reply Quote 2
                  • scottalanmillerS
                    scottalanmiller
                    last edited by

                    And actually, NTFS cares too. NTFS is case sensitive just like any other POSIX filesystem. NTFS is part of the POSIX family with EXT3, XFS, BtrFS, XFS, etc. It's actually the Windows Command Shell that strips this out. If you use BASH on Windows, everything is case sensitive again. It's a weird abstraction by the shell to make it all case sensitive under the hood, but presented to the end users differently.

                    BRRABillB 1 Reply Last reply Reply Quote 0
                    • BRRABillB
                      BRRABill @scottalanmiller
                      last edited by

                      I take it back then.

                      No one moving from Windows to Linux should have any issues with capitalization.

                      NOTE THIS IS SARCASM. IN ALL CAPS.

                      scottalanmillerS 1 Reply Last reply Reply Quote 0
                      • scottalanmillerS
                        scottalanmiller @BRRABill
                        last edited by

                        @BRRABill said in Linux: Using Top:

                        I take it back then.

                        No one moving from Windows to Linux should have any issues with capitalization.

                        NOTE THIS IS SARCASM. IN ALL CAPS.

                        They absolutely should not. It's not a Windows issue, its a cultural issue on Windows how ridiculous misuse of capitalization has been first accepted and then promoted. It's actually a bit crazy that even Windows users use it so oddly. It just doesn't make sense. It's been long enough since the no-lower case DOS days or the no shift key Apple ][ days that no one should be thinking of the world without capitalization today. Certainly no one on Windows since the Internet came about has actually been able to do that without things breaking. Abusing caps on Windows has made Windows users struggle unnecessarily all along.

                        BRRABillB 1 Reply Last reply Reply Quote 0
                        • BRRABillB
                          BRRABill @scottalanmiller
                          last edited by

                          @scottalanmiller said

                          its a cultural issue on Windows how ridiculous misuse of capitalization has been first accepted and then promoted. ... Abusing caps on Windows has made Windows users struggle unnecessarily all along.

                          You just supported my argument.

                          And I'm not necessarily even talking about filenames ... do you use a lot of Windows apps where CTRL-m and CTRL-M do different things? I sure don't.

                          scottalanmillerS 1 Reply Last reply Reply Quote 0
                          • scottalanmillerS
                            scottalanmiller @BRRABill
                            last edited by

                            @BRRABill said in Linux: Using Top:

                            @scottalanmiller said

                            its a cultural issue on Windows how ridiculous misuse of capitalization has been first accepted and then promoted. ... Abusing caps on Windows has made Windows users struggle unnecessarily all along.

                            You just supported my argument.

                            And I'm not necessarily even talking about filenames ... do you use a lot of Windows apps where CTRL-m and CTRL-M do different things? I sure don't.

                            Can't think of any that would NOT be case sensitive there. CTRL-x and CTRL-SHIFT-x are standardly case sensitive on Windows.

                            BRRABillB 1 Reply Last reply Reply Quote 0
                            • scottalanmillerS
                              scottalanmiller
                              last edited by

                              Any example of a little app on Windows you might use that is case sensitive... MS office.

                              1 Reply Last reply Reply Quote 0
                              • scottalanmillerS
                                scottalanmiller
                                last edited by

                                And of course the OS itself is.

                                1 Reply Last reply Reply Quote 0
                                • BRRABillB
                                  BRRABill @scottalanmiller
                                  last edited by

                                  @scottalanmiller said in Linux: Using Top:

                                  Can't think of any that would NOT be case sensitive there. CTRL-x and CTRL-SHIFT-x are standardly case sensitive on Windows.

                                  How so?

                                  They both do exactly the same thing.

                                  scottalanmillerS 1 Reply Last reply Reply Quote 0
                                  • scottalanmillerS
                                    scottalanmiller @BRRABill
                                    last edited by

                                    @BRRABill said in Linux: Using Top:

                                    @scottalanmiller said in Linux: Using Top:

                                    Can't think of any that would NOT be case sensitive there. CTRL-x and CTRL-SHIFT-x are standardly case sensitive on Windows.

                                    How so?

                                    They both do exactly the same thing.

                                    Not on Windows. Not on MS apps or any I know. What specialty app are you thinking of? And is it caused by having so few shortcuts that they double mapped them?

                                    BRRABillB 1 Reply Last reply Reply Quote 1
                                    • BRRABillB
                                      BRRABill @scottalanmiller
                                      last edited by

                                      @scottalanmiller said in Linux: Using Top:

                                      @BRRABill said in Linux: Using Top:

                                      @scottalanmiller said in Linux: Using Top:

                                      Can't think of any that would NOT be case sensitive there. CTRL-x and CTRL-SHIFT-x are standardly case sensitive on Windows.

                                      How so?

                                      They both do exactly the same thing.

                                      Not on Windows. Not on MS apps or any I know. What specialty app are you thinking of? And is it caused by having so few shortcuts that they double mapped them?

                                      I was just using Notepad. But I do see that in Word, CTRL+SHIFT+X does nothing. (Which is totally different than top where, for example, m and M both do different things.)

                                      Do you have an example of where CTRL-[letter] and CTRL-SHIFT-[letter} actually do different things?

                                      It's one things to just not have the SHIFT portion of it work, because why would anyone press SHIFT if they could more easily not. But it is another entirely to have each do something totally different.

                                      scottalanmillerS 1 Reply Last reply Reply Quote 0
                                      • scottalanmillerS
                                        scottalanmiller @BRRABill
                                        last edited by

                                        @BRRABill said in Linux: Using Top:

                                        @scottalanmiller said in Linux: Using Top:

                                        @BRRABill said in Linux: Using Top:

                                        @scottalanmiller said in Linux: Using Top:

                                        Can't think of any that would NOT be case sensitive there. CTRL-x and CTRL-SHIFT-x are standardly case sensitive on Windows.

                                        How so?

                                        They both do exactly the same thing.

                                        Not on Windows. Not on MS apps or any I know. What specialty app are you thinking of? And is it caused by having so few shortcuts that they double mapped them?

                                        I was just using Notepad. But I do see that in Word, CTRL+SHIFT+X does nothing. (Which is totally different than top where, for example, m and M both do different things.)

                                        Do you have an example of where CTRL-[letter] and CTRL-SHIFT-[letter} actually do different things?

                                        It's one things to just not have the SHIFT portion of it work, because why would anyone press SHIFT if they could more easily not. But it is another entirely to have each do something totally different.

                                        X was an variable for "a character" there. But Windows uses caps in handling of shortcuts. Each application makes their own choices, of course, but the Windows, Microsoft and the Windows ecosystem standard is to respect case. It is unique to file system names when accessed through the command shell or the NT shell that they are ignored. The OS, most applications, the filesystem - essentially everything is still case sensitive.

                                        You can see why it is bad. Remove it in one little place and Windows users often think it applies in all kinds of places that it does not. It's very confusing. I know what it exists (compatibility with DOS) but it's super weird and backwards. It's literally a holdover from the 80s and feels like it.

                                        BRRABillB 1 Reply Last reply Reply Quote 0
                                        • BRRABillB
                                          BRRABill @scottalanmiller
                                          last edited by

                                          @scottalanmiller

                                          But "respecting it" means nothing.

                                          In WIndows, pressing a key for a function only does that function, or nothing.

                                          I am taking about, for example, in top where

                                          m

                                          and

                                          M

                                          do two totally different things.

                                          scottalanmillerS 1 Reply Last reply Reply Quote 0
                                          • scottalanmillerS
                                            scottalanmiller @BRRABill
                                            last edited by

                                            @BRRABill said in Linux: Using Top:

                                            @scottalanmiller

                                            But "respecting it" means nothing.

                                            In WIndows, pressing a key for a function only does that function, or nothing.

                                            I am taking about, for example, in top where

                                            m

                                            and

                                            M

                                            do two totally different things.

                                            Right, an in WIndows it always does two different things. If you keep using it in places where both do nothing, you can make ANYTHING into "not sensitive". But that logic, nearly every letter on the keyboard does the same thing - nothing. So you just told me that WIndows isn't "key sensitive". See why that makes no sense?

                                            1 Reply Last reply Reply Quote 0
                                            • scottalanmillerS scottalanmiller referenced this topic on
                                            • 1 / 1
                                            • First post
                                              Last post