Outils pour utilisateurs

Outils du site


issue185:c_c

Ceci est une ancienne révision du document !


So we were discussing a problem on one of the pods at work, when my coworker made a comment I actually wholeheartedly agreed with. Why can’t Linux ship with htop by default? My reason? With modern multicore systems, I prefer seeing my logical CPUs separately when I open up htop. It seems that people who create containers have other ideas, so in that spirit, I would like to go over the basics of top for those of you that don’t know. Also as a refresher for me, as top does not ‘top’ my list, so-to-speak.

On my daily driver I use the GUI version, and my server has htop, so I don’t use top other than at work.

All that aside, top is one of those things you HAVE to know, be it for work or that lovely LPI exam you are going to write. Sorry to hear you failed that LPI Mr “I have been using Linux for 20 years” – you know who you are.

Know that you can run top without elevated privileges, but to get the most out of it, rather use elevated privileges; it just ensures that you have access to everything. Here is a quick factoid, it is called top as it sorts the most CPU intensive PID to the top. The main place top and htop differ is in the header. This is the other place you can find the load average, other than uptime (a favourite LPI question). That load average can be good or bad, depending on the amount of CPUs you have in your system. For you to see the CPUs in top, you need to press “1”. This goes for other tools too, like glances, I want to see ‘at a glance’ what my CPUs (plural) are doing, I don’t want to remember key bindings.

That second line gets important when you have a laptop, where you do not want processes burning battery, otherwise more running tasks are not a problem. The abbreviations are usually a sticking point for newbies. I will run through them here quickly, there are screenshots if you don’t want to open top on your system. (I’ll probably steal it off the Internet as it is a lot of typing).

• us: user cpu time (or) % CPU time spent in user space • sy: system cpu time (or) % CPU time spent in kernel space • ni: user nice cpu time (or) % CPU time spent on low priority processes • id: idle cpu time (or) % CPU time spent idle • wa: io wait cpu time (or) % CPU time spent in wait (on disk) • hi: hardware irq (or) % CPU time spent servicing/handling hardware interrupts • si: software irq (or) % CPU time spent servicing/handling software interrupts • st: steal time - - % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine

True story, I installed Ubuntu Budgie on my cousin’s PC as it was slow as molasses with Windows, and I noticed a value in ‘wa’. Now this can happen if your system is low on memory, when it constantly writes to the drive, but in his case it was that his BIOS was incorrectly configured and the SATA channel was in “compatible” / “legacy” mode and not AHCI.

The MIB mem and the MIB swap line, is the same as the free command (hello, LPI questions). As you can see from my screenshot, I have 4GB memory in my laptop, with 400MB free and about 1.6GB in use and cache. I recently opened my music player; it usually takes a second or two to open, but the second time around it is greased lightning as it is in that buff/cache. If you noticed, you would see my swap is starting to be used, which will slow my system down soon. :/ I say soon as usually it is inactive memory pages that get inserted first (my old man gripe about the new programming paradigm where “unused memory is wasted memory” comes into play here).

Anyway, time to make top work for us. Open top and press “f” to see the options. You should see this busy output – that can scare newbies.

Sorry newbies, you just have to shoulder through it. The selector is your space bar (“Space toggles display”, this meant pudding to me when I first saw it). You can select what you want (and do not want) with it. This becomes important when you need to see more in your limited display window. If you un-select what you don’t need, what is left will have more space to display information (so don’t select everything, OK?). Just hit the escape key when you are done and your new layout will await you. This is all controllable via a .rc file if you want persistence. Keep in mind that if you ran top with sudo and you run it again without, it will be default. As for the color difference between top and htop, you can use the “z” key to inject some color, but it is red and pink, not something I care about. As you can see, I/O granularity is sorely lacking at a glance, you don’t know what program is grinding your disk. Something Linux really needs in top, and yes I know about iotop, but again, not available in a vanilla container.

The last thing is the mouse support for those key shortcuts at the bottom of top. Sometimes, when F10 press does not work, or you have a keyboard without F-keys, you can click on the F10 for it to exit. This is actually handier than you think and has saved me many times before. This is sorely missing on top. (That sounds weird; it’s not inside, it’s on top!).

I have never needed to make top persistently look some way, the default is fine, but it is those extra steps that get to me. Why use three steps, when five will do?

Did I make a mistake? Something unclear? misc@fullcirclemagazine.org

issue185/c_c.1664716449.txt.gz · Dernière modification : 2022/10/02 15:14 de auntiee