Lab Manual OS

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

L. D.

College of Engineering
Opp Gujarat University, Navrangpura, Ahmedabad - 380015

LAB MANUAL
Branch: Computer Engineering

Operating System (3140702)


Semester: IV
Operating System (3140702)


Certificate

This is to certify that Mr./Ms. __________________________,


Enrollment Number________________ has satisfactorily completed the practical work in
_______________ subject at L D College of Engineering, Ahmedabad-380015.

Date of Submission: _______________

Sign of Faculty: _______________

Head of Department: _______________

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 1


Operating System (3140702)


Sr. CO AIM Date Page Grade Sign


No. No.

1 CO5 Study of Basic commands of Linux/UNIX.

2 CO5 Study of Advance commands and filters of


Linux/UNIX.

3 CO5 Write a shell script to display your name.

4 CO5 Write a shell script to accept two numbers from


user and display addition of it.

5 CO5 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.
6 CO5 Write a shell script to display multiplication table
of given number.

7 CO5 Write a shell script to illustrate switch case.

8 CO5 Write a shell script to find factorial of given


number n.

9 CO5 Write a shell script which will accept a number b


and display first n prime numbers as output.

10 CO5 Write a shell script which will generate first n


Fibonacci numbers like: 1, 1, 2, 3, 5, 13, …

11 CO5 Write a shell script to read n numbers as command


arguments and sort them in descending order.

12 CO5 Write a shell script to display all executable files,


directories and zero sized files from current
directory.
13 CO5 Write a shell script to check entered string is
palindrome or not.

14 CO5 Write a shell script to find the largest of three


numbers.

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 2


Operating System (3140702)


15 CO5 Write a shell script for converting a decimal to


binary, octal and hex equivalent.

16 CO5 Write a shell script to validate the entered date. (eg.


Date format is :dd-mm-yyyy).

17 CO5 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

18 CO5 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

19 CO5 Write an awk program using function, which


convert each word in a given text into capital.

20 CO2 Write a program for process creation using C. (Use


of gcc compiler).

21 CO2 Write a C Program to Implement Following CPU


Scheduling algorithms.
1. SJF 2. Round Robin
22 CO4 Write a C Program to Implement Following Page
Replacement algorithms.
1. FIFO 2.LRU

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 3


Operating System (3140702)


L. D. College of Engineering, Ahmedabad

Department of Computer Engineering


Subject Name: Operating System Subject Code: 3140702

Term: 2022-23

Rubrics ID Criteria Marks Good (2) Satisfactory (1) Need


Improvement (0)

RB1 Regularity 05 High (>70%) Moderate (40- Poor (0-40%)


70%)

RB2 Problem Analysis 05 Apt & Full Limited Very Less


& Development Identification of Identification of Identification of
of the Solution the Problem & the Problem / the Problem /
Complete Incomplete Very Less
Solution for the Solution for the Solution for the
Problem Problem Problem

RB3 Testing of the 05 Correct Solution Partially Very less correct


Solution as required Correct solution for the
Solution for the problem
Problem

RB4 Documentation 05 Documentation Not up to Proper format not


completed neatly. standard. followed,
incomplete.

SIGN OF FACULTY

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 4


Operating System (3140702)


L. D. College of Engineering, Ahmedabad


Department of Computer Engineering
LABORATORY PRACTICALS ASSESSMENT

Subject Name: Operating System


Term: 2022-23

Enroll. No.:
Class:
Pract. CO RB1 RB2 RB3 RB4 Total Date Faculty
No. No. Sign

10

11

12

13

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 5


Operating System (3140702)


14

15

16

17

18

19

20

21

22

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 6


Operating System (3140702)


GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD,


COURSE CURRICULUM
COURSE TITLE: Operating System
(Code: 3140702)
Degree Programmes in which this course is offered Semester in which offered

Computer Engineering 4th Semester

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

After learning the course the students should be able to:


1. Analyze the structure of OS and basic architectural components involved in OS design.
2. Compare and contrast various CPU scheduling algorithms.
3. Evaluate the requirements for the process synchronization and co-ordination in contemporary
operating system.

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 7


Operating System (3140702)


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.

4. TEACHING AND EXAMINATION SCHEME

5. SUGGESTED LEARNING RESOURCES


A. LIST OF BOOKS

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

B. LIST OF SOFTWARE / LEARNING WEBSITES

1. Cygwin
2. Linux / Unix
3. https://www.tutorialspoint.com/

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 8


Operating System (3140702)


Practical – 1
AIM: Study of Basic commands of Linux/UNIX.

 pwd: print current(working) directory .


 ls: lists the content of directory .
 cd: change the directory .
 mkdir: Used to create directory .
 rmdir: Removes the specified directory .
 cal: Displays the calendar of specific month .
 cp: Duplicates the content of source file to target file .
 rm: Used to delete files .
 mv: Used to rename the file or directory .
 chmod: Access permissions associated with a file or directory canbe changed using chmod
command .
 cat: This command displays the contents of the file specified .

 whoami: Displays the name of user .


 date: displays current system date, ask for new date to be changed.
 Echo: display text output
 Hostname: displays host name.
 Shutdown: shut down system

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 9


Operating System (3140702)


Practical – 2
AIM: Study of Advance commands and filters of Linux/UNIX.

 ifconfig: ifconfig command is used to configure the kernel-resident network interfaces . It is


used at boot time to set up interfaces as necessary.
 netstat: netstat command displays various network related information such as network
connections , routing tables ,interface statistics etc.
 nslookup: A network utility program used to obtain information about Internet servers .
 dig: dig is a tool for querying DNS name servers for information about host addresses , mail
exchanges and related information.
 tty: print the file name of the terminal connected to standard input.
 file : This command tells you if the object you are looking at is a file or a directory.
 find : Finds one or more files assuming that you know their approximate paths.
 history: history command is used to list out the recently executed commands in the number
line order.
 grep : It selects and prints the lines from a file which matches a given string or pattern.
 | (pipeline command): it is used to combine two or more commands.

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 10


Operating System (3140702)


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 ( _).

Variables are defined as follows:

Variable_name=variable_value

Name=”first”
Number=100;

To access the value stored in a variable, prefix its name with the dollar sign ($)

“echo” command is used to print output.


Syntax: echo “<string to be printed>”
“read” is used to input data from user.
Syntax: read <vname>

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 11


Operating System (3140702)


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"

sum=$(expr "$num1" + "$num2")


echo "sum=$sum"

 Program

 Output

Signature of Faculty: Grade:


Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 12
Operating System (3140702)


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

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 13


Operating System (3140702)


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 loop execute a set of commands until a condition is true.


Syntax:
until command
do
Statement(s) to be executed until command is true
done
Example:
a=0

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

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 14


Operating System (3140702)


do
# if a is equal to 5 break the loop
if [ $a == 5 ]
then
break
fi
echo "Iteration no $a"
done

 Program

 Output

Signature of Faculty: Grade:


Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 15
Operating System (3140702)


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

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 16


Operating System (3140702)


Practical – 8
AIM: Write a shell script to find factorial of given number n.

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 17


Operating System (3140702)


Practical – 9
AIM: Write a shell script which will accept a number b and display first n prime numbers
as output.

 Program

 Output

Signature of Faculty: Grade:


Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 18
Operating System (3140702)


Practical – 10
AIM: Write a shell script which will generate first n Fibonacci numbers like: 1, 1, 2, 3, 5,
13, …

 Program

 Output

Signature of Faculty: Grade:


Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 19
Operating System (3140702)


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

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 20


Operating System (3140702)


Practical – 12
AIM: Write a shell script to display all executable files, directories and zero sized files
from current directory.

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 21


Operating System (3140702)


Practical – 13
AIM: Write a shell script to check entered string is palindrome or not.

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 22


Operating System (3140702)


Practical – 14
AIM: Write a shell script to find the largest of three numbers.

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 23


Operating System (3140702)


Practical – 15
AIM: Write a shell script for converting a decimal to binary, octal and hex equivalent.

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 24


Operating System (3140702)


Practical – 16
AIM: Write a shell script to validate the entered date. (eg. Date format is :dd-mm-yyyy).

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 25


Operating System (3140702)


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

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 26


Operating System (3140702)


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

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 27


Operating System (3140702)


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

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 28


Operating System (3140702)


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

The fork() system call returns either of the three values −

 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

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 29


Operating System (3140702)


Practical – 21
AIM: Write a C Program to Implement Following CPU Scheduling algorithms.
1. SJF 2. Round Robin

 Program

 Output

Signature of Faculty: Grade:


Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 30
Operating System (3140702)


Practical – 22
AIM: Write a C Program to Implement Following Page Replacement algorithms.
1. FIFO 2.LRU

 Program

 Output

Signature of Faculty: Grade:

Computer Engineering Department, L. D. College of Engineering, Ahmedabad-15 31

You might also like