Interesting (somewhat hidden) feature of htop

Greetings!

While using testdisk to recover some data I accidentally deleted, I “discovered” a very interesting feature of the utility “htop” (which was referred to me by @cyclicalobsessive - many thanks!)

The “hidden” feature is the bottom row - particularly the functions that allow you to kill things by highlighting them, or (!!!) change the “niceness” of running applications.

Viz.:

InkedScreenshot at 2021-11-19 19-01-27_LI

Why is this interesting?

Well. . . . testdisk spends a lot of its time accessing disk drives - the one being recovered and the one being written to with the recovered data.

Factoid:
Linux gives disk operations a relatively low priority, preferring to cache data so that the entire machine doesn’t get bogged down waiting for the disk.

Problem:
Testdisk spends a lot of time accessing the disk.  Therefore testdisk runs slow as molasses, uphill, in the winter.

The solution is to change the process priority for testdisk, and the obvious solution is the “renice” command.  However, like many command line features, it’s fussy and if you make even a tiny mistake. . . .

With htop, you highlight the line you want to change, then press F7 if you want to increase its priority, (make the “nice” value lower), or F8 if you want to reduce its priority, (make it “nicer” to everyone else).

I dropped the “niceness” of testdisk to -10.  By comparison, most everything else has a niceness of zero and the hypervisor/virtual disk manager has a niceness of -20.

BTW, the concept of “niceness” goes back to the time when Unix machines, (like the Vax or Solaris systems), were true multi-user platforms with limited memory and resources.  If you were doing something that would take a lot of processor time and resources, (like prime-number theory stuff you were doing as a hobby), and everyone else on the system was hurrying to finish important projects for their final grades, you could be “nice” to everyone by saying “I don’t need this right away, it can wait” and increase it’s “niceness” thereby lowering the priority and letting everyone else “go first” instead of hogging the machine.

In my case, dropping the niceness of testdisk signals the system that this is more important and it should get priority.

2 Likes

I think I have not pressed (or even had an “F7” key) for nearly fifteen years. Thanks for the tip.

2 Likes