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)?

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

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

13
nice -n 15 command1 | nice -n <num> command2 | nice -n <num> command3

nice isn't used differently from any other command.

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

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 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.