inside the mind of a linux admin

don’t let it go bad, go nice.

So you’ve got a process that is taking forever to complete, and is killing your server.

Make it play nice.

What is nice?
You can run a program with modified scheduling priority using nice command (19 = least favorable):

# nice -n19 /path/to/your/script.sh

This will execute the script.sh with the lowest priority, meaning the system scheduler gives less resources to it. Values range from -19 to 19, where the lower the number the higher the priority.

Just because you started a process without nice or ionice, does not mean you can’t change its’ priority to “baby it” back to normalcy.

For more information on how to do this, check out renice (man renice).

=======================================================

Disk I/O nice
ionice is what you want to use when you’ve got a process that is driving your disks insane.

How do I use ionice command?

Linux refers the scheduling class using following number system and priorities:

Scheduling class Number Possible priority
real time 1 8 priority levels are defined denoting how big a time slice a given process will receive on each scheduling window
best-effort 2 0-7, with lower number being higher priority
idle 3 Nil ( does not take a priority argument)

To display the class and priority of the running process, enter:

# ionice -p {PID}
# ionice -p 1

Sample output:

none: prio 0

Dump full web server disk / mysql backup using best effort scheduling (2) and 7 priority:

# /usr/bin/ionice -c2 -n7 /root/scripts/my/script.sh

There is no “reionice”, but the same functionality can be achieved using the ionice tool, like so (where 25374 is the PID# you want to reionice):

# ionice -p25374 -c2 -n7

Finally, you can also combine both nice and ionice together:

# nice -n 19 ionice -c2 -n7 /path/to/shell.script

Related Posts

synergy: How to enable crypto (encryption) and generate SSL certificate

The newer Linux versions of the popular mouse/keyboard sharing application “synergy” now has built in encryption. Here’s how to configure it: Just simply passing the –enable-crypto flag on your synergy server without having a proper SSL certificate will result in the inability to connect to clients and generate an error message similar to this in […]

Read More

Change Number Pad Delete (dot) key from a comma in Ubuntu Linux

I recently purchased a new keyboard and updated to the latest Ubuntu, I’m also an avid user of the number pad for quick input when dealing with spreadsheets or accounting. I found that my num pad’s delete key (“.”) was outputting a comma (“,”) instead. Pretty annoying? I agree, but this can be very easily […]

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.