Assign priority to commands executed from the terminal

Have you ever dreamed of running a command from terminal, limiting the amount of allocated resources to that command?

Well, the solution presented here can help you to continue working normally even moments after executing jobs that are usually "too heavy" for you. hardware and that they generally "hang" the system.

Processor (CPU)

The nice command allows modifying the priority of a process over the rest within the system.

The Linux kernel is in charge of planning and allocating CPU time to each of the processes that run on the system. The available priority assignment range is -20 to 20, with -20 being the highest priority and 20 being the lowest.

Thanks to nice we can ensure that in times of high CPU usage the appropriate processes receive the highest% of it.

The syntax for the nice command is as follows:

nice -n COMMAND

So, if we wanted to run a process with priority 10 we would do the following:

nice -n10 / usr / bin / convert file.gif file.jpg

Hard drive

Similar to nice is ionice, with the difference that the latter limits access to the hard drive.

An example of its use would be the following:

ionice -c2 -n7 / usr / bin / convert file.gif file.jpg

-c2 is "best effort", and -n7 is the lowest priority within "best effort". In this way, this command will have a lower priority within the I / O (input / output) queue than the rest of the running tasks.

ionice -c3 / usr / bin / convert file.gif file.jpg

-c3 (no need to clarify a priority level) means "inactive only". Jobs with -c3 assigned to them will only run when the disk is idle, which means that the activity will have no impact on the execution of the rest of the tasks, but will take much longer to execute itself.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

3 comments, leave yours

Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Daniel pedroza said

    I need to mention the renice command, which is used to modify the priority of the processes already running

  2.   Let's use Linux said

    Interesting! Thanks for the contribution!
    Cheers! Paul.

  3.   vinsuk said

    And how is that done in win? d8-B