Manage an application's priority in Linux - gHacks Tech News

Manage an application's priority in Linux

In the land of Linux applications have what is called their "nice" value. This value sets the priority that any given application receives. The nice value ranges from -20 to 19. The lower the number the higher the priority. The higher the priority the the more CPU time a program will get. This comes in handy, say if you are rendering a video that is going to take a long time and can consume a good amount of your CPU cycles. You can set the nice value to give that process a lower priority so it won't consume that much of your CPU. The job will take longer, but you won't notice the huge hit on your processor. But how is this done? Let's take a look at how you can manage the priority of an application.

"nice" and "renice"

We'll start this with the command line method of changing these values (I'll demonstrate the GUI method in a moment). There are two commands you need to know: nice and renice. You use nice to launch a command with a specific nice value. You use renice when you want to change the priority of a program that is already running. Let's see how those commands are used.

In order to launch an application with a specific nice value you would issue the command:

nice APPLICATION NICE_VALUE

Where APPLICATION is the command used to launch the application and NICE_VALUE is the priority (from -20 to 20) that you want to launch the application with.

Now, to change the nice value of an application already running you would use the renice command like so (NOTE: If you are wanting to renice a service or an application that was started with administrative privileges you must have administrative privileges to run renice, so you'll need to either su to root or use sudo):

renice NICE_VALUE APPLICATION_PID

Where NICE_VALUE is the new nice value you want to assign to a process and APPLICATION_PID is the process ID of the application. NOTE: You can't renice with an application name like you can with nice.

Using a GUI

Figure 1

There is, of course, a much easier way of handling this task. If you open up the System Monitor you will notice a Nice column (see Figure 1). If you select an application and right-click it you will notice the Change Priority entry in the menu. Select that and a new window will appear with a slider allowing you to change the nice value from -20 to 20. Once you have changed that value click the Change Priority button and the new nice value is set.

You will probably notice that the majority of applications nice value is set to 0. That is normal priority. You will only want to change this value for certain circumstances - such as a run-away application or when an application will consume a good amount of CPU cycles. Other than that, Linux does a fairly good job managing the priority of the applications both the system and the users run. But it's always nice to know you can step in when necessary.

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:

Comments

  1. Joseph Ruscio said on January 13, 2011 at 2:42 am
    Reply

    Good article about `nice`. If you’re interested in controlling and monitoring/visualizing groups of processes (e.g. complex applications) on Linux you could check out Librato Silverline (full disclosure: I hack here). Would love any feedback you might have.

  2. Dotan Cohen said on January 14, 2011 at 11:25 pm
    Reply

    Thanks, Jack! I did not know about renice.

  3. Troy Rose said on February 19, 2011 at 8:29 am
    Reply

    Also, this somewhat crude ability to reprioritize tasks under linux is being revamped somewhat with the introduction of control groups, which give you the ability to prioriizes io, cpu, cpusets, network packet prioritization – which goes a very long way to possibly elminate nice altogether.

  4. Troy Rose said on February 19, 2011 at 8:32 am
    Reply

    Also, this somewhat crude ability to reprioritize tasks under linux is being revamped somewhat with the introduction of control groups, which give you the ability to prioritize io, cpu, cpusets (cpu affinity), network packet prioritization – which goes a very long way to possibly eliminate nice altogether.

    On top of that, there are some really cool visualisation tools that take advantage of control groups:
    http://cgfreak.sourceforge.net/

  5. Liva said on August 10, 2013 at 6:49 am
    Reply

    xrenice project, like xkill lets you to renice priority by one click on app.
    On GitHub – https://github.com/firebbs/xrenice

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.