You are on page 1of 40

St.

Thomas' College of Engineering and Technology

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

Laboratory Manual
OPERATING SYSTEM LABORATORY
Code: CS 693

Name: ____________________________
University Roll No: _____________________
College Roll No: _______________________
Year:___________ Semester: _________
Section: _________ Group:____________
Session: _____________________________

1
Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

General Information

Course Operating System


Semester 6
Name Laboratory

Course Year with 3rd CSE


CS 693
Code stream

Course 2 Session
Credit

Faculty Class hours 3 hours/week per batch in


Instructor/s DC/AH/SSk/BDu/APC and total Even semester
class load

Technical Laboratory
Assistant/s

1. To familiarize students with the Linux environment


Course 2. To learn the fundamentals of shell scripting/programming
objectives
3. Implementing various Process and Memory Management
algorithms.

1. Will able to describe and write shell scripts in order to perform


basic shell programming
Course
Outcomes
2. We will able to describe and write C programs for process
handling.

2
Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

PO PO Description
Number

PO1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals and an engineering specialization to the solution of complex engineering
problems.

PO2 Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principle of
mathematics, natural science and engineering sciences.

PO3 Design / development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.

PO4 Design / development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.

PO5 Modern tool usage: Create, select, apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations

PO6 The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.

PO7 The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.

PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.

PO9 Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.

PO10 Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations,
and give and receive clear instructions

PO11 Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend
Page: ___ / ___
Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

and write effective reports and design documentation, make effective presentations,
and give and receive clear instructions

PO12 Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations,
and give and receive clear instructions

PO CO

CO 1 CO 2 CO 3

PO 1

PO 2

PO 3

PO 4

PO 5

PO 6

PO 7

PO 8

PO 9

PO
10

PO
11

PO
12

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Safety Norms and precautions

1. Install any unlicensed software.


Do not 2. Insert pen drive without permission.
3. Handle any equipment without reading the instructions /Instruction manuals.
4. Use Mobile Phones during the lab session.
5. Come late in the laboratory. Late comers without proper reason and permission of HOD
will not be allowed to enter the lab.

1. Strictly observe the instructions given by the Teacher/ Lab Instructor.


2. It is mandatory to come to lab in formal dress (College uniform, ID card, and Shoes).
3. It is mandatory to come with observation book and lab record in which previous
experiment should be written in Record and the present labs experiment in Observation
book.
Do
4. Observation book of the present lab experiment should get corrected on the same day
and Record should be corrected on the next scheduled lab session.
5. Prepare for the viva questions. At the end of the experiment, the lab faculty will ask the
viva Questions and marks are allotted accordingly.

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Course policies

1. Attendance
Attendance is compulsory. Please be respectful to your classmates by being on time. Cell
phones should be turned off and kept out of sight.

2. Calculator policy

You may need a calculator device.

3. Plagiarism

Collaboration on performing the experiments and taking measurements is strongly encouraged;


however, the lab report you hand in must be solely your own. Sharing written work beforehand
is considered as academic dishonesty.

4. Disability Support

If you have a disabling condition which may interfere with your ability to successfully complete
this module, please contact Faculty in charge.

5. Make-up Experiment

Make-up for a missing experiment will not be offered, normally. The only exceptions to that are
illness or emergency (e.g., death in family, a traffic accident, etc.), in which case you may
contact your faculty in charge.

6. Beyond Syllabus Experiment

As per policy you have to perform at least one beyond syllabus experiment from the list of
beyond syllabus experiments provided in Part II.

7. Experiment in virtual laboratory

As per policy you have to perform at least one virtual laboratory experiment. You may select
your virtual experiments from:.

8. Micro Project

As per policy you have to perform at least one micro project.

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Course assessment process

Continuous assessment
Lab reports [15%]
Experiment number, Objective, theory, procedure, results, discussion and conclusion.

Lab applications & attendance [20%]


Performance on method of working, titrating, reading data, tabulating data, plotting graph,
attendance etc.

Questions and quizzes at the end of each experiment (5%)

Assessment during end semester examination


Lab examination [40%]
Experiments are allotted to the students randomly on lottery basis during examination time
which they have to complete within stipulated time.

Viva [20%]
There is a 10-minute viva-voce during examination time.

Grading Scale
Grade Percent score
0 90

E 80 and <90

A 70 and <80

B 60 and <70

C 50 and <60

D 40 and <50

F <40

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

1) Sumitabha Das, UNIX: Concepts & Application, Tata McGraw Hill, 4 th


Recommended Edn., 2008.
2) Brian Beej Jorgensen Hall, Beejs guide to Unix IPC, 2015.
books 3) W.R. Stevens, S.A.Rago, Advanced Programming in the Unix
environment, Pearson, Third Edn., 2013.
List of Experiments

Assg. Name of Experiment Page Date of Grade Signature


No. Number Expt. awarded

01 a) Introduction to LINUX Commands

01 b) Advanced UNIX commands

01 c) UNIX Filters

02a) Introduction to Shell Programming

02b) Control Structures in Shell

02c) Loop Control in Shell

02d) Advanced Shell Programming


03
C in LINUX Environment
04
Memory Management
05
Process Management
06
Assignment outside Syllabus
07
Virtual Laboratory
08
Micro Project

Assignment 01

Title: Introduction to LINUX Commands

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Objective: To know different types of LINUX commands for different purpose.

1. Satisfy ____________________________________ of Blooms Taxonomy.

2. Achieve of ____________________________________Program Outcomes.

Theory:

Basic Commands
Linux
Description
Command
date The date command tells the system to print the date and time
cal Displays calendar
who show who is logged on
echo Display text on the screen. Mostly useful when writing shell scripts
bc Basic calculator

Commands for Navigating the Linux File systems


Linux DOS
Description
Command Command
Print Working Directory. Shows the current location
pwd dir
in the directory tree.
Change Directory. When typed all by itself, it returns
cd cd, chdir
you to your home directory.

ls dir /w List all files in the current directory, in column format.


List files in long format, one file per line. This also
ls l dir shows you additional info about the file, such as
ownership, permissions, date, and size.
List all files, including hidden files. Hidden files are
ls a dir /a those files that begin with a ., e.g. The
.bash_history file in your home directory.

Working with Files and Directories


Linux Command DOS Command Description
Creates a blank file
touch edit
eg. touch sample
file Find out what kind of file it is.

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

For example, file /bin/ls tells us that it is a Linux


executable file.
cat type Display the contents of a text file on the screen.
head Display the first few lines of a text file.
tail Display the last few lines of a text file.
cp copy Copies a file from one location to another.
mv rename, ren, move Moves a file to a new location, or renames it.
rm del Delete a file.
mkdir md Make Directory.
rmdir rd, rmdir Remove Directory.
Lists the contents of directories in a tree-like
tree
format.

Searching For Files

Linux Command Description


which Shows the full path of shell commands found in your path.
Locates the program, source code, and manual page for a command
whereis
(if all information is available).
locate A quick way to search for files anywhere on the file system.
A very powerful command, but sometimes tricky to use. It can be used
find to search for files matching certain patterns, as well as many other
types of searches.

Informational Commands
Linux Command Explanation
ps Lists currently running process (programs)
w Show who is logged on and what they are doing
id Print user-id and group id's
Displays CPU processes in a full-screen GUI. A great way to see
top
the activity on your computer in real-time. Type Q to quit.
free Displays amount of free and used memory in the system.
Prints system information to the screen (kernel version, machine
uname a
type, etc.)
wc Print the number of newlines, words, and bytes in files

System Administration

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Linux Command Description


Switch User. Allows you to switch to another user's account
su temporarily. The default account to switch to is the root/superuser
account.
chmod Change permissions on a file
chown Change file owner and group
passwd Update a users authentication tokens(s)

uptime Used to find the duration for which the system has been running

Other Utilities
Linux
Description
Command
clear Clear the screen
more Display a file, or program output one page at a time.
An improved replacement for the more command. Allows you to scroll
less
backwards as well as forwards.
grep Search for a pattern in a file or program output.
lpr Print a file or program output.
sort Sort a file or program output.

Problem statement:

Program:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Discussions:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Questionnaires:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Grade awarded:

Teachers signature with date ___________________________

Assignment 02
Title: Introduction to Shell Programming
Objective: To get familiar with shell program

1. Satisfy ____________________________________ of Blooms Taxonomy.

2. Achieve ____________________________________of Program Outcomes.

Theory:
Writing a Shell Script:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Step 1: To create a shell script, open a new empty file in your editor. Any text editor will do: vi,
emacs, gedit, dtpad etc. are all valid.
Step 2: Put UNIX commands or your statements in the new empty file, like you would enter them
on directly in the command line.
Step 3: Give your script a sensible name that gives a hint about what the script does. Make sure
that your script name does not conflict with existing commands. In order to ensure that no
confusion can rise, script names often end in .sh; even so, there might be other scripts on your
system with the same name as the one you chose. Check using which, whereis and other
commands for finding information about programs and files.
Commands and Syntaxes for Shell Programming:
(1) echo [options] [string, variables...]
Displays text or variables value on screen.
(2) if...else...fi
If given condition is true then command1 is executed otherwise command2 is executed.
Syntax:
if condition
then
command1 if condition is true or if exit status
of condition is 0(zero)
...
...
else
command2 if condition is false or if exit status
of condition is >0 (nonzero)
...
...
fi
(3) Multilevel if-then-else
Syntax:
if condition
then
condition is zero (true 0)
execute all commands up to elif statement
elif condition1
condition1 is zero (true 0)

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

execute all commands up to elif statement


elif condition2
condition2 is zero (true 0)
execute all commands up to elif statement
else
None of the above condtion,condtion1,condtion2 are true (i.e.
all of the above nonzero or false)
execute all commands up to fi
fi
(4) for loop
Syntax:
for { variable name } in { list }
do
execute one for each item in the list until the list is
not finished (And repeat all statement between do and done)
done
(5) while loop
Syntax:
while [ condition ]
do
command1
command2
command3
..
....
done

(6) The case Statement


The case statement is good alternative to multilevel if-then-else-fi statement. It enables you to match
several values against one variable. Its easier to read and write.
Syntax:
case $variable-name in
pattern1) command
...
Page: ___ / ___
Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

..
command;;
pattern2) command
...
..
command;;
*) command
...
..
command;;
esac
(7) The read Statement Use to get input from keyboard and store them to variable.
Syntax:
read varible1, varible2,...varibleN
Command Line Arguments:
(1) The $# Variable
Whenever you execute a shell program, the special shell variable $# gets set to the number of
arguments that were typed on the command line.
(2) The $* Variable
The special variable $* references all the arguments passed to the program. This is often useful in
programs that take an indeterminate or variable number of arguments.
(3) The $0 Variable
Whenever you execute a shell program, the shell automatically stores the name of the program inside
the special variable $0. This can be used to advantage when you have two or more programs that are
linked under different names and you want to know which one was executed. Its also useful for
displaying error messages because it removes the dependency of the filename from the program. If the
name of the program is referenced by $0, subsequently renaming the program will not require the
program to be edited
Arrays:
Array indexing starts at zero. An array element is accessed with a subscript, which is an integer-valued
expression enclosed inside a pair of brackets. You dont declare the maximum size of a shell array; you
simply assign values to elements as you need them. The values that you can assign are the same as
for ordinary variables.
$ arr[0]=hello
$ arr[1]=some text
To retrieve an element from an array:
$ echo ${array[0]}
Page: ___ / ___
Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

hello
$ echo ${array[1]}
some text
Basic Operators in Shell Scripts:
Relational Operators
Operator Description Example
Checks if the values of two operands are equal
-eq [ a eqb ] is not true.
or not, if yes then condition becomes true.
Checks if the values of two operands are equal
-ne or not, if values are not equal then condition [ a neb ] is true.
becomes true.

Checks if the value of left operand is greater


-gt than the value of right operand, if yes then [ a gtb ] is not true.
condition becomes true.
Checks if the value of left operand is less than
-lt the value of right operand, if yes then condition [ a ltb ] is true.
becomes true.
Checks if the value of left operand is greater
-ge than or equal to the value of right operand, if [ a geb ] is not true.
yes then condition becomes true.
Checks if the value of left operand is less than
-le or equal to the value of right operand, if yes [ a leb ] is true.
then condition becomes true.

Boolean Operators
Operator Description Example
This is logical negation. This inverts a true
! [ ! false ] is true.
condition into false and vice versa.

This is logical OR. If one of the operands is true [ a lt20 ob gt 100 ] is


-o
then condition would be true. true.

This is logical AND. If both the operands are


[ a lt20 ab gt 100 ] is
-a true then condition would be true otherwise it
false.
would be false.

Executing a Shell Script:


If script_name.sh is the name of source shell program, then to execute it you have type
./script_name.sh
Page: ___ / ___
Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

or
sh script_name.sh

Problem Statement:

Program:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Discussions:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Questionnaires:
Page: ___ / ___
Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Grade awarded:

Teachers signature with date _______________________

Assignment 03
Title: Memory Management
Objective: To manage memory using Linked List method and implement Allocation Algorithms.

1. Satisfy _____________________________________ of Blooms Taxonomy.

2. Achieve ____________________________________of Program Outcomes.

Theory: One of the simplest methods for memory allocation is to divide memory into several fixed-
sized partitions. Each partition may contain exactly one process. In this multiple-partition method, when
a partition is free, a process is selected from the input queue and is loaded into the free partition. When
the process terminates, the partition becomes available for another process. The operating system
keeps a table indicating which parts of memory are available and which are occupied. Finally, when a
process arrives and needs memory, a memory section large enough for this process is provided. When
it is time to load or swap a process into main memory, and if there is more than one free block of
memory of sufficient size, then the operating system must decide which free block to allocate. Best-fit
strategy chooses the block that is closest in size to the request. First-fit chooses the first available block
that is large enough. Worst-fit chooses the largest available block.

Problem statement:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Program:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Discussions:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Questionnaires:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Grade awarded:

Teachers signature with date ________________________

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Assignment 04
Title: Process Management
Objective: To create child process.

1. Satisfy _____________________________________ of Blooms Taxonomy.

2. Achieve ____________________________________of Program Outcomes.

Theory:
Parent and Child Process:
Each UNIX process has two ID numbers assigned to it: Process ID (pid) and Parent process
ID (ppid). In the Unix operating system, every process except process 0 (the swapper) is
created when another process executes the fork() system call. The process that invoked fork is
the parent process and the newly created process is the child process. Every process (except
process 0) has one parent process, but can have many child processes.
Process 0 is a special process that is created when the system boots; after forking a child
process (process 1), process 0 becomes the swapper process (sometimes also known as the
"idle task"). Process 1, known as init, is the ancestor of every other process in the system.

Problem statement:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Program:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Discussions:

Questionnaires:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Grade awarded:

Teachers signature with date _______________________

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Assignment 05
Title: Understanding Orphan and Zombie Process
Objective: To create orphan and zombie Process

1. Satisfy ____________________________________ of Blooms Taxonomy.

2. Achieve ____________________________________of Program Outcomes.

Theory:
Zombie Process:

The operating system maintains a table that associates every process, by means of its process
identifier (generally referred to as "pid") to the data necessary for its functioning. When a process
terminates its execution, the operating system releases most of the resources and information related
to that process, but still keeps the data about resource utilization and the termination status code,
because a parent process might be interested in knowing if that child executed successfully and the
amount of system resources it consumed during its execution.

By default, the system assumes that the parent process is indeed interested in such information at the
time of the child's termination, and thus sends the parent the signal SIGCHLD to alert that there is
some data about a child to be collected. Such collection is done by calling a function of the wait family.
As soon as this collection is made, the system releases those last bits of information about the child
process and removes its pid from the process table. However, if the parent process lingers in collecting
the child's data (or fails to do it at all), the system has no option but keep the child's pid and termination
data in the process table indefinitely. Such a terminated process whose data has not been collected is
called a zombie process, or simply a zombie, in the UNIX parlance.

Orphan Process:

Orphan processes are an opposite situation to zombie processes, referring to the case in which a
parent process terminates before its child processes, which are said to become "orphaned". Unlike the
asynchronous child-to-parent notification that happens when a child process terminates (via the
SIGCHLD signal), child processes are not notified immediately when their parent finishes. Instead, the
system simply redefines the "parent PID" field in the child process's data to be the process that is the
"ancestor" of every other process in the system, whose PID generally has the value of 1 (one), and
whose name is traditionally "init". Thus, it is said that init "adopts" every orphan process on the system.

The exec family of functions replaces the program running in a process with another program. When a
program calls an exec function, that process immediately ceases executing that program and begins
executing a new program from the beginning, assuming that the exec call doesnt encounter an error.
There shall be no return from a successful exec, because the calling process image is overlaid by the
new process image.

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Problem statement:

Program:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Discussions:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Questionnaires:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Grade awarded:

Teachers signature with date _______________________

Beyond Syllabus Experiment

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Title: File Management

Objective: To know different types of file allocation techniques through C programming in


LINUX

1. Satisfy _____________________________________ of Blooms Taxonomy.

2. Achieve ____________________________________of Program Outcomes.

Theory:

Sequential File Allocation


In this file organization, the records of the file are stored one after another both physically and logically.
That is, record with sequence number 16 is located just after the 15 th record. A record of a sequential
file can only be accessed by reading all the previous records.
Linked File Allocation
With linked allocation, each file is a linked list of disk blocks; the disk blocks may be scattered
anywhere on the disk. The directory contains a pointer to the first and last blocks of the file. Each block
contains a pointer to the next block.
Indexed File Allocation
Indexed file allocation strategy brings all the pointers together into one location: an index block. Each
file has its own index block, which is an array of disk-block addresses. The i th entry in the index block
points to the ith block of the file. The directory contains the address of the index block. To find and read
the ith block, the pointer in the 39th index-block entry is used.

Problem statement:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Program:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Discussions:

Questionnaires:

Page: ___ / ___


Department of Computer Science and Engineering

St. Thomas College of Engineering and Technology

Grade awarded:

Teachers signature with date ___________________________

Page: ___ / ___

You might also like