What is the nicest a Unix command can be?

mahemoff

For a quick benchmarking test, how can nice and ionice be combined to maximum effect, ie for a command to use as little resource as possible (without idling altogether)?

(I think it's something like `nice -n 19 ionice -c 2 [command], but not sure about ionice's "-n" (classdata param), the man page is cryptic about its relevance.)

Austin Hemmelgarn

The full command you want is:

chrt -b 0 nice -n 19 ionice -c 2 -n 7 [command]

The chrt command at the beginning will switch things to the batch scheduling class, which is equivalent to adding 0.5 to the nice value. The -n option for ionice is a simple priority for the realtime (-c 1) and best-effort (-c 2) options, with lower values being higher priority just like nice values (but in the range 0-7). However, the ionice command is not strictly necessary, since I/O scheduling class and priority are by default derived from the CPU scheduling parameters, and nice -n 19 implies ionice -c 2 -n 7.

However, you can get the absolute minimal resource usage by setting both the CPU and I/O scheduling classes to idle. In both cases, the 'idle' schedulers aren't actually idle schedulers, and you will still be able to use resources, it's just that everything will have higher priority.

For the CPU scheduling class, this also uses the chrt command, albeit without needing nice (priority must be set to 0 in the idle scheduling class), and looks like this:

chrt -i 0 {command or PID}

The nice command on Linux mirrors the SVR4 version, which means that it can't change scheduling class, only nice value (which also behaves differently on Linux than classical UNIX, but that's a bit OT). As the original alternative scheduling classes were the POSIX.1E realtime SCHED_RR and SCHED_FIFO, the command to set scheduling classes ended up being called chrt. The -i option specifies to use the SCHED_IDLE scheduling class

For the I/O scheduling class, you use ionice. The exact command looks like this:

ionice -c 3 {command or PID}

The -c option specifies what scheduling class to use, and 3 is the number for the idle class. Note that depending on which block I/O scheduler is being used, this may not actually impact anything. In particular, the noop I/O scheduler doesn't support priorities or scheduling classes at all, and I'm pretty sure the deadline schedulers (both the legacy one, and the blk-mq one) don't either.

If you want to do this programmatically, either for your own program, or to adjust things for other processes, check out the man pages for the sched_setscheduler and ioprio_set system calls (although both are worth reading if you just want more background too).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the nicest way to weight planes in a numpy array?

From Dev

What is the unix history command "!$" in bash?

From Dev

What are the limits of whois command on unix?

From Dev

What's the nicest way to wait for a promise initiated on a directive to resolve?

From Dev

MS SQL: What is the easiest/nicest way to create a linked server with SSMS?

From Dev

MS SQL: What is the easiest/nicest way to create a linked server with SSMS?

From Dev

what is equivalent command of unix which in VMS

From Dev

What does set -e command does in Unix?

From Dev

What does "cat -A" command option mean in Unix

From Dev

What is the effect of using a # in front of a UNIX command?

From Dev

What does the name of the unix command apropos mean?

From Dev

What does this symbol mean in my Unix command?

From Dev

What does dash "-" mean in Unix command line?

From Dev

What does "cat -A" command option mean in Unix

From Dev

What was the first Unix platform to have the 'yes' command?

From Dev

What does the Unix login program/command do?

From Dev

How can I optimize this Unix command?

From Dev

Can someone explain the meaning of -- and ** in a linux/unix command?

From Dev

What Unix commands can be used as a semaphore/lock?

From Dev

what does the + and the - symbols indicate when a "jobs" command is executed in unix?

From Dev

What Unix command-line program prints holidays?

From Dev

What do the parentheses and number after a Unix command or C function mean?

From Dev

what does the + and the - symbols indicate when a "jobs" command is executed in unix?

From Dev

what is the equivalent perl and python code for unix command "mdb hostname"

From Dev

what is the difference in output for ps -www and ps command in unix

From Dev

What is equivalent for $(command) of UNIX-like terminal in Windows terminal?

From Dev

What is the Unix (QNX) equivalent of Windows command line "dir /s /b"

From Dev

What is the unix command to find out what executable file corresponds to a given command?

From Dev

How can i do "-" * 60 for Unix command line

Related Related

  1. 1

    What is the nicest way to weight planes in a numpy array?

  2. 2

    What is the unix history command "!$" in bash?

  3. 3

    What are the limits of whois command on unix?

  4. 4

    What's the nicest way to wait for a promise initiated on a directive to resolve?

  5. 5

    MS SQL: What is the easiest/nicest way to create a linked server with SSMS?

  6. 6

    MS SQL: What is the easiest/nicest way to create a linked server with SSMS?

  7. 7

    what is equivalent command of unix which in VMS

  8. 8

    What does set -e command does in Unix?

  9. 9

    What does "cat -A" command option mean in Unix

  10. 10

    What is the effect of using a # in front of a UNIX command?

  11. 11

    What does the name of the unix command apropos mean?

  12. 12

    What does this symbol mean in my Unix command?

  13. 13

    What does dash "-" mean in Unix command line?

  14. 14

    What does "cat -A" command option mean in Unix

  15. 15

    What was the first Unix platform to have the 'yes' command?

  16. 16

    What does the Unix login program/command do?

  17. 17

    How can I optimize this Unix command?

  18. 18

    Can someone explain the meaning of -- and ** in a linux/unix command?

  19. 19

    What Unix commands can be used as a semaphore/lock?

  20. 20

    what does the + and the - symbols indicate when a "jobs" command is executed in unix?

  21. 21

    What Unix command-line program prints holidays?

  22. 22

    What do the parentheses and number after a Unix command or C function mean?

  23. 23

    what does the + and the - symbols indicate when a "jobs" command is executed in unix?

  24. 24

    what is the equivalent perl and python code for unix command "mdb hostname"

  25. 25

    what is the difference in output for ps -www and ps command in unix

  26. 26

    What is equivalent for $(command) of UNIX-like terminal in Windows terminal?

  27. 27

    What is the Unix (QNX) equivalent of Windows command line "dir /s /b"

  28. 28

    What is the unix command to find out what executable file corresponds to a given command?

  29. 29

    How can i do "-" * 60 for Unix command line

HotTag

Archive