Site icon DataFlair

ionice Command in Linux with Examples

linux ionice command

FREE Online Courses: Transform Your Career – Enroll for Free!

In this article, we will learn everything about the ionice command in Linux-based operating systems. We will look at what the ionice command is, why it is used, how to install it, the syntax of the ionice command, and the options used along with it. In the end, we will also look at some fantastic practical examples of the ionice command by pairing it with various options to understand its working. So pay attention, take notes, and read all the way to the end for the best benefits.

What is linux ionice command?

ionice is a command line-based utility in Linux-based operating systems that helps in encouraging the director to dole out needs on a process cycle level to accelerate or to confine the disk subsystem use of a particular cycle.

Let us understand the geeky definition of the ionice command by taking an instance where we need to run a rsync order or content to reinforce your documents either locally or distantly. We use ionice alone with the rsync language structure to accelerate or confine the rsync cycle.

In a nutshell, the ionice command sets or shows both the I/O class and priority within that class. There are 4 types of classes, they are:
1. None
2. Realtime
3. Best Effort
4. Idle

Understanding the scheduling classes

Even though there are 4 scheduling classes, the kernel considers “None” and “Best Effort” as the same thing. Let us look at each of the 3 classes in slightly more detail.

1. Realtime:

The real-time scheduling class is given the first access to the disk, regardless of what is going on in the system. This is the exact reason why the real-time scheduling class needs to be treated with care, if not, it can starve other processes. This class has a priority ranging from 0 – 7, where 0 is the highest priority and 7 is the least.

2. Best Effort:

The Best effort scheduling class is the default for any process that has not asked for a specific io priority. Just like the real-time scheduling class, the best effort class also has 8 priority levels, ranging from 0 – 7, where the lower number has higher priority. The programs that run at the same best-effort priority are executed in a round-robin fashion.

3. Idle:

As the name suggests, a program running with idle io priority will only get disk time when no other program has asked for disk io for a specific period. The idle scheduling class does not take a priority argument.

Syntax of Linux ionice command

The syntax of the ionice command might look slightly intimidating at first, but once we understand the fields present in the syntax, it will become a cakewalk! The syntax of the ionice command is shown below:

ionice -c <scheduling class> -n <priority value> <options><command>

Let us take a closer look at the fields present in the syntax of the ionice command

1. <scheduling class>

This field takes in the name of the scheduling class. You can choose anything from idle, real-time, and best effort.

2. <priority value>

This field takes in the value of the priority values. This field is applicable only for scheduling classes “real-time” and “best effort”. You can specify any priority value from 0 to 7.

3. <options>

This field takes in a range of options that specify how the ionice command must function, format, and print the output.

4. <command>

This field takes the actual command, we will see examples of this when we look at how to use the ionice command in later sections.

Options used with ionice command in linux

Unlike most commands in Linux, the ionice command comes with very few options, let us take a detailed look at each.

1. -c

This option determines the name or number of the scheduling class to utilize; 0 for none, 1 for real-time, 2 for best-exertion, and 3 for inactive. You can also write this option as “–class”

2. -n

This option determines the scheduling of class information. You can also write this option as “–classdata”

3. -p

This option indicates the cycle IDs of running cycles for which to get or set the scheduling boundaries. You can also write this option as “–pid”

4. -h

This option displays the help menu of the ionice command as shown below:

#image#

5. -t

This option overlooks the inability to set the mentioned need. You can also write this option as “–ignore”

6. -u

This option indicates the client IDs of running cycles for which to get or set the scheduling boundaries. You can also write this option as “–uid”

7. -P

This option indicates the cycle bunch IDs of running cycles for which to get or set the scheduling boundaries. You can also write this option as “–pgid”

8. -V

This option shows information regarding the version of ionice you are using on your computer as shown:

Now, since we have covered the theory and fundamentals regarding the ionice command, let us look at some fantastic examples of the ionice command in the terminal of ubuntu 20.04.

Setting a PID and specifying scheduling class in linux

If you want to set a specific process identity and also specify a scheduling class, use the following syntax:

ionice -c <scheduling class> -p <PID>

For example, the command “sudo ionice -c 3 -p 1” will set a process with a process identity of 1 and be an idle i/o (3) process

Running a command as a best effort program

To run a command as a best effort program, you have to run the ionice command by pairing it with the option “-c” followed by the number “2” which represents the ‘best effort’ scheduling class as shown in the syntax below:

ionice -c 2 <command>

For example, the command “ionice -c 2 bash” will run the bash command as a best-effort program.

Printing class and priority of a process

To print the scheduling class and priority of a process having a specific PID, use the syntax shown below:

ionice -p <PID1> <PID2>

For example the command “ionice -p 1 2” will print the class and priority of the process having PID 1 or 2.

Prints IDs of running processes

To get the IDs of running processes, execute the ionice command by combining it with the option “u” as shown below:

Overlooking the inability related to the process

If you want to overlook any inability related to the process, all you have to do is run the ionice command by pairing it with the option “-t” as shown.

#image#

Summary

As you have seen the ionice command is a simple utility that helps in specifying the scheduling class and priority levels for a program. You have now understood what the ionic command is, why it is used, the syntax of the ionice command, and the various options used with it.

Exit mobile version