15

I need to execute a set of "piped" commands with altered niceness level. Example:

nice -n 15 command1 | command2 | command3

In this case niceness is altered to "15" only for command1. How to change it for the whole set of commands (command1, command2 and command3)?

Wargalis
  • 151
  • 1
  • 3

3 Answers3

19
 nice -n 15 sh -c "command1 | command2 | command3"

This sets niceness of a subshell, and the commands 1..3 inherit it.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
rozcietrzewiacz
  • 38,754
  • 9
  • 94
  • 102
13
nice -n 15 command1 | nice -n <num> command2 | nice -n <num> command3

nice isn't used differently from any other command.

Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
nils
  • 131
  • 2
0

exec command{1..26} runs all commands numbered 'command1' all the way to 'command26'

nice -n 15 $(pgrep command) renices any running process with 'command' in it

jjisnow
  • 161
  • 1
  • 2
  • 1
    `command` is very likely just a place holder. – ploth Nov 19 '18 at 10:30
  • I think there is a "race" condition here in that if any of the commands forks or starts another process, that one won't get picked up when changing the niceness. The other two answers set niceness at start so new processes will inherit that value – nijave Apr 10 '21 at 21:27