In a multitasking operating system (which Linux is), the kernel is responsible for assigning CPU time for each process running on the system. Only one process at a time can actually be running in the CPU, so the kernel assigns CPU time to each process in turn.
By default, all processes started from the shell have the same scheduling priority on the Linux system. The scheduling priority is the amount of CPU time the kernel assigns to the process relative to the other processes.
The scheduling priority is an integer value, from −20 (the highest priority) to +20 (the lowest priority). By default, the bash shell starts all processes with a priority of 0.
This means that a simple script that only requires a little bit of processing time gets the same CPU time slices as a complex mathematical algorithm that can take hours to run.
Sometimes you want to change the priority of a specific command, either lowering its priority so that it doesn’t take as much processing power from the CPU or giving it a higher priority so that it gets more processing time. You can do this by using the nice command.
The nice command
The nice command allows you to set the scheduling priority of a command as you start it. To make a command run with less priority, just use the -n command line option for nice to specify a new priority level:$ nice -n 10 ./test4 test4out &
The nice command causes the script to run at a lower priority. However, if you try to increase the priority of one of your commands, you might be in for a surprise:
$ nice: cannot set priority: Permission denied
+ Exit 1 nice -n -10 ./test4 >test4out
The nice command prevents normal system users from increasing the priority of their commands. This is a safety feature to prevent a user from starting all of his or her commands as high priority.
The renice command
Sometimes you’d like to change the priority of a command that’s already running on the system. That’s what the renice command is for. It allows you to specify the PID of a running process to change the priority of:$ ./test4 test4out
The renice command automatically updates the scheduling priority of the running process. Just as with the nice command, the renice command has some limitations:
If you want to fully control running processes, you must be logged in as the root account.
Shell Scripting Related Interview Questions
|Perl Scripting Interview Questions||Python Interview Questions|
|Linux Interview Questions||Linux Embedded systems Interview Questions|
|AWK Interview Questions||BioPerl Interview Questions|
|Sed (Stream Editor) Interview Questions||Advanced Linux Interview Questions|
|Unix/Linux Interview Questions||Unix Shell Scripting Interview Questions|
Shell Scripting Tutorial
Starting With Linux Shells
Getting To The Shell
Basic Bash Shell Commands
More Bash Shell Commands
Using Linux Environment Variables
Basic Script Building
Understanding Linux File Permissions
Working With Editors
Using Structured Commands
More Structured Commands
Handling User Input
Adding Color To Scripts
Introducing Sed And Gawk
The Ash Shell
The Tcsh Shell
The Korn Shell
The Zsh Shell
Using The Web
Using A Database
Shell Script For Administrators
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.