Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

share|improve this question

migrated from Jul 20 '12 at 11:37

This question came from our site for professional and enthusiast programmers.

As others have said, the simple answer is yes. The children will inherit niceness from the parent. As demonstrated here:… – ltn100 Jul 19 '12 at 13:14
up vote 4 down vote accepted

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
share|improve this answer

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.

share|improve this answer

You must log in to answer this question.