You are on page 1of 17

Setting priority on new processes

At this point you are probably wondering how you can set
your own priority levels on processes. To change the priority
when issuing a new command you do nice -n [nice value]
[command]:
nice -n 10 apt-get upgrade
This will increment the default nice value by a positive 10
for the command, ‘apt-get upgrade‘ This is often useful for
times when you want to upgrade apps but don’t want the
extra process burden at the given time. Remember a
positive number is gives less priority for a process.

Setting Priority on Existing Processes
Obviously at some point you are going to want to alter the
nice value of something that is already running. Just the
other day I was doing an upgrade to Ubuntu Jaunty and
Firefox started to become unusably slow. A quick renice
command rescheduled the upgrade to a lower priority and I
was back to surfing in no time.
To change the priority of an existing process just do renice
[nice value] -p [process id]:
renice 10 -p 21827
This will increment the priority of the process with an id of
21827 to 10.

you can type a command. is issued by the shell. which is called command prompt. programs. Shell prompt:  The prompt.Note: Only root can apply negative nice values.  It gathers input from you and executes programs based on that input. Shell scripting:  The shell provides you with an interface to the UNIX system. and shell scripts. While the prompt is displayed.  A shell is an environment in which we can run our commands. There are different flavors of shells. $.  For eg: $ date Case-esac program in shell scripting: Syntax: case word in .

. pattern3) Statement(s) to be executed if pattern3 matches. ..... esac Note: * indicates default value. 3)echo “THREE”. Esac Example 1: echo ‘Enter any value between 1 to 5’ read num case $num in 1)echo “ONE” .pattern1) Statement(s) to be executed if pattern1 matches . 4)echo “FOUR”. *)echo “INVALID VALUE”. 2)echo “TWO”. 5)echo “FIVE”. pattern2) Statement(s) to be executed if pattern2 matches.....

If…else: Comparisons: -eq equal to -ne not equal to -lt less than -le less than or equal to -gt greater than -ge greater than or equal to If-else program: Syntax: if [ expression ] then Statement(s) to be executed if expression is true else Statement(s) to be executed if expression is not true fi Example 2: valid_password=”welcome” .

Echo “Enter your password” read PSWD if [ “$PSWD” = “$valid_password” ] then echo “Valid password” else echo “Access denied” fi Example 3: Echo “Enter the number” Read num If test $num –le 30 Then echo “Number is less than equal to 30” else echo “Number is greater than 30” fi if… then… elif: .

Syntax: if [ expression 1 ] then Statement(s) to be executed if expression 1 is true elif [ expression 2 ] then Statement(s) to be executed if expression 2 is true elif [ expression 3 ] then Statement(s) to be executed if expression 3 is true else Statement(s) to be executed if no expression is true fi Example 4: echo “enter the value of a” read a echo “enter the value of b” read b .

if [ $a = $b ] then echo “a is equal to b” elif [ $a –gt $b ] then echo “a is greater than b” elif [ $a –lt $b ] then echo “a is less than b” else echo “INVALID VALUE” fi While loop: Syntax: while command do Statement(s) done Example 5: .

echo “Enter the value of a” read a while [ $a -lt 5 ] do a=`expr $a + 1` echo $a done For loop: Syntax: for (( EXP1. EXP2. EXP3 )) do command1 command2 command3 done Example 6: for((c=1.c++)) do echo “Welcome to STC” .c<=5.

done Until loop: Syntax: until command do Statement(s) Done Example 7: a=1 until [ $a –ge 5 ] do echo “ $a .Welcome to STC” a=$(($a + 1)) done PASSING PARAMETERS: Example 8: (inside a shell program) Echo “First value is $1” .

It then steps down to the code following the end of the loop.Echo “Second value is $2” Echo “Third value is $3” (outside shell program. during execution) sh name. Syntax: Break Example 9: a=0 while [ $a –lt 10 ] do echo $a if [ $a –eq 5 ] then break .sh 10 20 30 Breaking out of loops: The break statement is used to terminate the execution of the entire loop. after completing the execution of all of the lines of code up to the break statement.

This statement is useful when an error has occurred but you want to try to execute the next iteration of the loop. Syntax: Continue Example 10: NUMS="1 2 3 4 5 6 7" for NUM in $NUMS do Q=`expr $NUM % 2` if [ $Q -eq 0 ] then echo "Number is an even number!!" . rather than the entire loop.fi a=`expr $a + 1` done The continue statement: The continue statement is similar to the break command. except that it causes the current iteration of the loop to exit.

> Returns “True”. [ $a -lt 20 -a $b -gt . if both condition1 and condition2 are “True” (Like AND operator) || -------. This is logical OR.> Returns “True”. If one of the operands is true then condition would be true. If any one condition is “True” (Like OR operator) Boolean Operators: There are following boolean operators supported by Bourne Shell. Assume variable a holds 10 and variable b holds 20 then: Operator ! -o -a Description This is logical negation.continue fi echo "Found odd number" done LOGICAL OPERATORS: && -------. This inverts a true condition into false and vice versa. If both Example [ ! false ] is true. This is logical AND. [ $a -lt 20 -o $b -gt 100 ] is true.

otherwise it would be false. Example 11: (For “||” operator) echo “Enter the value of a” read a echo “Enter the value of b” read b if (( a == 1 )) | | (( b == 8 )). . b : True if the file exists and is a block special file.the operands are true then condition would be true 100 ] is false.then echo “Enable!!!” else echo “Disable” fi FILE TEST OPERATORS: The different file test operators are listed below: a : True if the file exists.

O : True if the file exists and is owned by the effective user ID. x : True if the file exists and is executable. u : True if the file exists and its SUID (set user ID) bit is set. h : True if the file exists and is a symbolic link. k : True if the file exists and its sticky bit is set. s : True if the file exists and has a size greater than zero. w : True if the file exists and is writable. L : True if the file exists and is a symbolic link. G : True if the file exists and is owned by the effective group ID. f : True if the file exists and is a regular file.c : True if the file exists and is a character special file. t : True if file descriptor is open and refers to a terminal. e : True if the file exists. r : True if the file exists and is readable. . d : True if the file exists and is a directory. p : True if the file exists and is a named pipe (FIFO). g : True if the file exists and its SGID bit is set.

S : True if the file exists and is a socket. for write “ if [ -w $file ]” and for execute “ if [ -x $file ] “) Then Echo “Read access” Else Echo “Read permission denied” fi .sh” If [-r $file ] (similarly.sh is an already existing file) file=”bud. Syntax: (mostly used in “if-loop”) if [ -option filename ] then do something else do something fi Example 12: (bud.N : True if the file exists and has been modified since it was last read.

. Set -x: Display commands and their arguments as they are executed.sh Use of set built in command Bash shell offers debugging options which can be turn on or off using set command. $ Bash -x script-name $ bash -x domains.Example 13: File=”directory1” If [ -d $file ] Then Echo “Directory is present” Else Echo “Directory is not present” fi Debugging Shell Scripts: -x option to debug a shell script Run a shell script with -x option.

sh .sh Bash –v filename. How to execute: Bash –x filename.Set -v: Display shell input lines as they are read.