6

Does nice work on any shell script, or does it work on basic Linux commands only?

For example, if I have a custom shell script that contains a sort function, and I call

nice myscript.sh

would the nice scheduling priority apply to sort in the script? Would nice still work if myscript.sh is running in the background (using & or nohup)?

Bill the Lizard
  • 946
  • 2
  • 13
  • 29
  • As others have said, the simple answer is yes. The children will inherit niceness from the parent. As demonstrated here: http://www.linuxforums.org/forum/newbie/96715-using-nice-script.html#post479756 – ltn100 Jul 19 '12 at 13:14

2 Answers2

4

Yes, the nice command can be used with scripts. Actually, assuming you are using bash, the nice command will be applied to bash and all its possible child processes. The nice priority is not altered when a process is running on the background.

You can just test it yourself and see that nice indeed affects the priority of a bash script. Just execute any script you want, and then use ps to see the priorities:

ps -eo pid,pri,cmd
betabandido
  • 262
  • 3
  • 8
2

Nice applies to the process that is started when running the command and any child processes. So the answer to your question is yes, it does work on any commands/scripts, even if they are put into the background.

Lars Kotthoff
  • 1,543
  • 11
  • 9