Lab Manual OS
Lab Manual OS
Lab Manual OS
College of Engineering
Opp Gujarat University, Navrangpura, Ahmedabad - 380015
LAB MANUAL
Branch: Computer Engineering
Certificate
Term: 2022-23
SIGN OF FACULTY
Enroll. No.:
Class:
Pract. CO RB1 RB2 RB3 RB4 Total Date Faculty
No. No. Sign
10
11
12
13
14
15
16
17
18
19
20
21
22
1. RATIONALE
• To study basics of computer system and operating system, its functions, types, evolution.
• To study fundamental concepts of process, threads, process management, process scheduling
algorithms and inter process communication.
• To understand situation that causes deadlock and solution for the prevention and recovery after
deadlock.
• To study concepts of memory management, issues and algorithms for memory management.
• To study various I/O management and disk scheduling techniques.
• To study the risk and security aspect of operating system.
• To study Unix /Linux operating system and virtualization concept.
2. COMPETENCY
The course content should be taught to impart knowledge about operating system which is most
important component of any computer system. The aim of the course is to enable students to
understand fundamentals of operating system, different task performed by operating system,
different approaches to perform the task, prone and cons of various approaches.
3. COURSE OUTCOMES
4. Analyze various algorithms for memory management, I/O management and security aspects of
operating system.
5. Write shell scripts in Unix/Linux O.S and write simple programs using kernel system calls.
Also understand virtualization concept.
1. Operating Systems: Internals & Design Principles, 9th Edition, William Stallings, Pearson Education
India
2. Operating System Concepts, 9th edition Peter B. Galvin, Greg Gagne, Abraham Silberschatz, John
Wiley & Sons, Inc.
3. Modern Operating Systems-By Andrew S. Tanenbaum (PHI)
4. Unix shell programming in Linux by yashwant kanetkar
1. Cygwin
2. Linux / Unix
3. https://www.tutorialspoint.com/
Practical – 1
AIM: Study of Basic commands of Linux/UNIX.
Practical – 2
AIM: Study of Advance commands and filters of Linux/UNIX.
Practical – 3
AIM: Write a shell script to display your name.
Theory: A shell script is a computer program designed to be run by the Unix/Linux shell. A
shell is a command-line interpreter and typical operations performed by shell scripts
include file manipulation, program execution, and printing text. The shell is a
programming language, complete with variables, control structures etc.
Variable Names
The name of a variable can contain only letters (a to z or A to Z), numbers (0 to 9) or
the underscore character ( _).
Variable_name=variable_value
Name=”first”
Number=100;
To access the value stored in a variable, prefix its name with the dollar sign ($)
Program
Output
Practical – 4
AIM: Write a shell script to accept two numbers from user and display addition of it.
Theory: read the two numbers using “read” command. Sum of two numbers can be performed
using expression. There are various operators supported by each shell.
Following example shows addition of two numbers.
val=`expr 2 + 2`
echo "Total value : $val"
val=`expr $a + $b`
echo "Total value : $val"
Program
Output
Practical – 5
AIM: Write a shell script to generate mark sheet of a student. Take 3 subjects, calculate
and display total marks, percentage and Class obtained by the student.
Theory: This program need to use else…if decision making structure to display class obtained
by student. Syntax of else..if is as per below.
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:
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 "None of the condition met"
fi
Program
Output
Practical – 6
AIM: Write a shell script to display multiplication table of given number.
Theory: This program needs to use loop. The while loop enables you to execute a set of
commands repeatedly until some condition occurs. Syntax of while loop is given below.
Syntax:
while command
do
Statement(s) to be executed if command is true
done
Example:
a=0
while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
until [ ! $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
for The for loop operate on lists of items. It repeats a set of commands for every item in a list.
Syntax:
for var in word1 word2 ...wordn
do
Statement to be executed
done
Example:
for a in 1 2 3 4 5 6 7 8 9 10
do
# if a is equal to 5 break the loop
if [ $a == 5 ]
then
break
fi
echo "Iteration no $a"
done
Program
Output
Practical – 7
AIM: Write a shell script to illustrate switch case.
Theory: Shell supports case...esac statement for switch case. It does so more efficiently than
repeated if...elif statements.
Syntax:
case word in
pattern1)
Statement(s) to be executed if pattern1 matches
;;
pattern2)
Statement(s) to be executed if pattern2 matches
;;
pattern3)
Statement(s) to be executed if pattern3 matches
;;
*)
Default condition to be executed
;;
esac
Example:
FRUIT="kiwi"
case "$FRUIT" in
"apple") echo "Apple pie is quite tasty."
;;
"banana") echo "I like banana nut bread."
;;
"kiwi") echo "New Zealand is famous for kiwi."
;;
Esac
Program
Output
Practical – 8
AIM: Write a shell script to find factorial of given number n.
Program
Output
Practical – 9
AIM: Write a shell script which will accept a number b and display first n prime numbers
as output.
Program
Output
Practical – 10
AIM: Write a shell script which will generate first n Fibonacci numbers like: 1, 1, 2, 3, 5,
13, …
Program
Output
Practical – 11
AIM: Write a shell script to read n numbers as command arguments and sort them in
descending order.
Theory: To input arguments into a Bash script, like any normal command line program, there
are special variables set aside for this. The arguments are stored in variables with a number in the
order of the argument starting at 1
First Argument: $1
Second Argument: $2
Third Argument: $3
Following code will get number of values from command in array variable. Length of variable
can be used to find the number of input. Here array of number will be defined.
nos=( "$@" )
len=${#nos[@]}
echo "$len"
Program
Output
Practical – 12
AIM: Write a shell script to display all executable files, directories and zero sized files
from current directory.
Program
Output
Practical – 13
AIM: Write a shell script to check entered string is palindrome or not.
Program
Output
Practical – 14
AIM: Write a shell script to find the largest of three numbers.
Program
Output
Practical – 15
AIM: Write a shell script for converting a decimal to binary, octal and hex equivalent.
Program
Output
Practical – 16
AIM: Write a shell script to validate the entered date. (eg. Date format is :dd-mm-yyyy).
Program
Output
Practical – 17
AIM: Write a menu driven shell script which will print the following menu and execute
the given task.
a. Display calendar of current month
b. Display today’s date and time
c. Display usernames those are currently logged in the system
d. Display your name at given x, y position
e. Display your terminal number
f. Exit
Program
Output
Practical – 18
AIM: Write a shell script to display the menu. It should take appropriate action when an
option is selected.
a. List directory.
b. Copy file
c. Rename a file
d. Delete a file
e. Edit a file
f. Exit
Program
Output
Practical – 19
AIM: Write an awk program using function, which convert each word in a given text
into capital.
Theory: Awk is a scripting language used for manipulating data and generating reports. Awk is
mostly used for pattern scanning and processing. It searches one or more files to see if they
contain lines that match with the specified patterns and then perform the associated actions.
AWK Operations:
(a) Scans a file line by line
(b) Splits each input line into fields
(c) Compares input line/fields to pattern
(d) Performs action(s) on matched lines
Below line will convert content of csv file into uppercase.
awk '{print toupper($0)}' data.csv
Program
Output
Practical – 20
AIM: Write a program for process creation using C. (Use of gcc compiler).
Theory:
fork(): Fork system call is used for creating a new process, which is called child
process, which runs concurrently with the process that makes the fork() call (parent
process).
Syntax:
fork()
Negative value to indicate an error, i.e., unsuccessful in creating the child process.
Returns a zero for child process.
Returns a positive value for the parent process. This value is the process ID of the
newly created child process.
Program
Output
Practical – 21
AIM: Write a C Program to Implement Following CPU Scheduling algorithms.
1. SJF 2. Round Robin
Program
Output
Practical – 22
AIM: Write a C Program to Implement Following Page Replacement algorithms.
1. FIFO 2.LRU
Program
Output