Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com 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: linuxforums.org/forum/newbie/… –  ltn100 Jul 19 '12 at 13:14
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.