0% found this document useful (0 votes)
80 views58 pages

Ise Os Lab Manual

lab manual

Uploaded by

Devi Bala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views58 pages

Ise Os Lab Manual

lab manual

Uploaded by

Devi Bala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 58

MVJ22IS32-OPERATING SYSTEMS LAB

An Autonomous Institute
NEAR ITPB, CHANNASANDRA, BENGALURU – 560 067
Affiliated to VTU, Belagavi
Approved by AICTE, New Delhi
Recognized by UGC under 2(f) & 12(B)
Accredited by NBA & NAAC

DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING


III SEMESTER
OPERATING SYSTEMS
MVJ22IS32
ACADEMIC YEAR 2023– 2024(ODD)

LABORATORY MANUAL
NAME OF THE STUDENT :

BRANCH :

UNIVERSITY SEAT NO. :

SEMESTER & SECTION :

BATCH :

DEPT OF ISE 1
MVJ22IS32-OPERATING SYSTEMS LAB

DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING

VISION:

To create an enriching learning environment where talented and industry-ready ISE professionals are nurtured.
This is our promise!

MISSION:

 To develop skilled and knowledgeable professionals in the field of ISE.


 To impart high-quality education and career-oriented learning programs.
 To contribute towards increased and better performance.
 To benefit the society through our contribution towards advancements in Information science and
Engineering.

Programme Educational Objectives (PEOs):

PEO01: Current Industry Practices: Graduates will analyze real world problems and give solution using
current industry practices in computing technology.

PEO02: Research & Higher Studies: Graduates with strong foundation in mathematics and engineering
fundamentals will pursue higher learning, R&D activities and consultancy.

PEO03: Social Responsibility: Graduates will be professionals with ethics, who will provide industry growth
and social transformation as responsible citizens.

Programme Outcomes (POs):

Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.

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

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.

Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.

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

DEPT OF ISE 2
MVJ22IS32-OPERATING SYSTEMS LAB

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.

Environment and sustainability: Understand the impact of the professional engineering solutions in societal
and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.

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

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

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.

Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.

Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and
life-long learning in the broadest context of technological change.

Program Specific Outcome:

PSO1 : Programming: Ability to understand, analyze and develop computer programs in the areas related to
algorithms, system software, multimedia, web design, DBMS, and networking for efficient design of
computer-based systems of varying complexity.

PSO2: Practical Solution: Ability to practically provide solutions for real world problems with a broad range
of programming language and open source platforms in various computing domains.

Course objectives:
To Demonstrate the need for OS and different types of OS
To discuss suitable techniques for management of different resources
To demonstrate different APIs/Commands related to processor, memory, storage and file system management

Course outcomes:
At the end of the course, the student will be able to:
CO 1. Explain the structure and functionality of operating system
CO 2. Apply appropriate CPU scheduling algorithms for the given problem.
CO 3. Analyse the various techniques for process synchronization and deadlock handling. CO CO 4. Apply the
various techniques for memory management
CO 5. Explain file and secondary storage management strategies. CO 6. Describe the need for information
protection mechanisms

Prerequisites:
Basic programming Languages like C.

DEPT OF ISE 3
MVJ22IS32-OPERATING SYSTEMS LAB

CONTENTS
Sl.N Experiments
O
1 Develop a c program to implement the Process system calls (fork (), exec(), wait(), create process,
terminate process)

2 Simulate the following CPU scheduling algorithms to find turnaround time and waiting time a)
FCFS
b) SJF c) Round Robin d) Priority.
3 Develop a C program to simulate producer-consumer problem using semaphores.

4 Develop a C program which demonstrates interprocess communication between a reader


process and a writer process. Use mkfifo, open, read, write and close APIs in your
program.
5 Develop a C program to simulate Bankers Algorithm for DeadLock Avoidance.

6 Develop a C program to simulate the following contiguous memory allocation Techniques:


a) Worst fit b) Best fit c) First fit.
7 Develop a C program to simulate page replacement algorithms:
a) FIFO b) LRU

8 Simulate following File Organization Techniques


a) Single level directory b) Two level directory
9 Develop a C program to simulate the Linked file allocation strategies.

10 Develop a C program to simulate SCAN disk scheduling algorithm.

Assessment Details (both CIE and SEE)


The weight age of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam (SEE) is
50%. The minimum passing mark for the CIE is 40% of the maximum marks (20 marks out of 50) and
for the SEE minimum passing mark is 35% of the maximum marks (18 out of 50 marks). A student shall
be deemed to have satisfied the academic requirements and earned the credits allotted to each subject/
course if the student secures a minimum of 40% (40 marks out of 100) in the sum total of the CIE
(Continuous Internal Evaluation) and SEE (Semester End Examination) taken together.

CIE for the theory component of the IPCC (maximum marks 50)
1. IPCC means practical portion integrated with the theory of the course.
2. CIE marks for the theory component are 25 marks and that for the practical component is 25
marks.
3. 25 marks for the theory component are split into 15 marks for two Internal Assessment Tests
(Two Tests, each of 15 Marks with 01-hour duration, are to be conducted) and 10 marks for other
assessment methods

DEPT OF ISE 4
MVJ22IS32-OPERATING SYSTEMS LAB

mentioned in 22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the second test
after covering 85-90% of the syllabus.
1. Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for
the theory component of IPCC (that is for 25 marks).
2. The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of
IPCC.CIE for the practical component of the IPCC
3. 15 marks for the conduction of the experiment and preparation of laboratory record, and 10
marks for the test to be conducted after the completion of all the laboratory sessions.
4. On completion of every experiment/program in the laboratory, the students shall be evaluated
including viva-voce and marks shall be awarded on the same day.
5. The CIE marks awarded in the case of the Practical component shall be based on the continuous
evaluation of the laboratory report. Each experiment report can be evaluated for 10 marks. Marks of
all experiments’ write-ups are added and scaled down to 15 marks.
6. The laboratory test (duration 02/03 hours) after completion of all the experiments shall be
conducted for 50 marks and scaled down to 10 marks.
7. Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory
component of IPCC for 25 marks.
8. The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of
the IPCCSEE for IPCCTheory SEE will be conducted by University as per the scheduled
timetable, with common question papers for the course (duration 03 hours)[The question paper
will have ten questions. Each question is set for 20 marksThere will be 2 questions from each
module. Each of the two questions under a module (with a maximum of 3 sub-questions), should
have a mix of topics under that moduleThe students have to answer 5 full questions, selecting one
full question from each module]Marks scoredby the student shall be proportionally scaled down to 50
Marks]The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical
portion will have a]CIE component only. Questions mentioned in the SEE paper may include
questions from the practical component

BASICS OF UNIX COMMANDS

DEPT OF ISE 5
MVJ22IS32-OPERATING SYSTEMS LAB

INTRODUCTION TO UNIX
BASICS OF UNIX COMMANDS
BASIC UNIX COMMANDS
AIM:
To study
UNIX:
It is a multi-user operating system. Developed at AT & T Bell Industries, USA in 1969.
Ken Thomson along with Dennis Ritchie developed it from MULTICS (Multiplexed Information and
Computing Service) OS. By1980, UNIX had been completely rewritten using C language.

LINUX:
It is similar to UNIX, which is created by Linus Torualds. All UNIX commands works in Linux. Linux is a
open source software. The main feature of Linux is coexisting with other OS such as windows and UNIX.

STRUCTURE OF A LINUXSYSTEM:
It consists of three parts.
 UNIX kernel
 Shells
 Tools and Applications

UNIX KERNEL:
Kernel is the core of the UNIX OS. It controls all tasks, schedule all Processes and carries out all the functions
of OS. Decides when one programs tops and another starts.

SHELL:
Shell is the command interpreter in the UNIX OS. It accepts command from the user and analyses and
interprets them

AIM:
To study of Basic UNIX Commands and various UNIX editors such as vi, ed, ex and EMACS.

DEPT OF ISE 6
MVJ22IS32-OPERATING SYSTEMS LAB

CONTENT:
Note: Syn->Syntax

date :
used to check the date and time
Syn: $date

Format Purpose Example Result


+%m To display only month $date+%m 06
+%h To display month name $date+%h June
+%d To display day of month $date+%d O1
+%y To display last two digits of years $date+%y 09
+%H To display hours $date+%H 10
+%M To display minutes $date+%M 45
+%S To display seconds $date+%S 55

cal:
–used to display the calendar
Syn: $cal 2 2009

echo:
–used to print the message on the screen.
Syn: $echo “text”

ls:
–used to list the files. Your files are kept in a directory.
Syn: $lsls–s

All files (include files with prefix)


ls–l: Lodetai (provide file statistics)
ls–t: Order by creation time
ls– u: Sort by access time (or show when last accessed together with –l) ls–s Order by size
ls–r: Reverse order
ls–f:Mark directories with /,executable with* , symbolic links with @, local sockets with =, named
pipes(FIFOs)with
ls–s: Show file size
ls– h:“ Human Readable”, show file size in Kilo Bytes & Mega Bytes (h can be used together with –l or)
ls[a-m] *: List all the files whose name begin with alphabets From „a‟ to „m‟ ls[a]*List all the files whose
name begins with „a‟ or „A‟
E.g.: $ls>my list Output of „ls‟ command is stored to disk file named „my list‟

lp :
–used to take printouts
Syn: $lp filename

man
–used to provide manual help on every UNIX commands.
Syn: $man unix command

DEPT OF ISE 7
MVJ22IS32-OPERATING SYSTEMS LAB

$man cat

who &whoami
–it displays data about all users who have logged into the system currently. The next command displays about
current user only.
Syn: $who$whoami

uptime
–tells you how long the computer has been running since its last reboot or power-off.
Syn: $uptime

uname
–it displays the system information such as hardware platform, system name and processor, OS type.
Syn: $uname–a

hostname
–displays and set system host name
Syn: $ hostname

bc
–stands for „best calculator‟

$bc $ bc $ bc $ bc
10/2*3 scale =1 ibase=2 sqrt(196)
15 2.25+1 obase=16 14 quit
3.35 11010011
quit 89275
1010
Ā
Quit
$bc $ bc-l
for(i=1;i<3;i=i+1)I scale=2
1 s(3.14)
2 0
3 quit

FILE MANIPULATION COMMANDS


cat–this create, view and concatenate files.

Creation:
Syn: $cat>filename

Viewing:

DEPT OF ISE 8
MVJ22IS32-OPERATING SYSTEMS LAB

Syn: $cat filename

Add text to an existing file:


Syn: $cat>>filename

Concatenate:
Syn: $catfile1file2>file3
$catfile1file2>>file3 (no over writing of file3)

grep–used to search a particular word or pattern related to that word from the file.
Syn: $grep search word filename
Eg: $grep anu student

rm–deletes a file from the file system


Syn: $rm filename

touch–used to create a blank file.


Syn: $touch file names

cp–copies the files or directories


Syn: $cp source file destination file
Eg: $cp student stud

mv–to rename the file or directory


Syn: $mv old file new file
Eg: $mv–i student student list (-i prompt when overwrite)

cut–it cuts or pickup a given number of character or fields of the file.


Syn: $cut<option><filename>
Eg: $cut –c filename
$cut–c1-10emp
$cut–f 3,6emp
$ cut –f 3-6 emp
-c cutting columns
-f cutting fields

head–displays10 lines from the head(top)of a given file


Syn: $head filename
Eg: $head student
To display the top two lines:
Syn: $head-2student

tail–displays last 10 lines of the file


Syn: $tail filename
Eg: $tail student
To display the bottom two lines;
Syn: $ tail -2 student

chmod–used to change the permissions of a file or directory.


Syn: $ch mod category operation permission file Where, Category–is the user type
DEPT OF ISE 9
MVJ22IS32-OPERATING SYSTEMS LAB

Operation–is used to assign or remove permission


Permission–is the type of permission
File–are used to assign or remove permission all

Examples:
$chmodu-wx student
Removes write and execute permission for users
$chmodu+rw,g+rwstudent
Assigns read and write permission for users and groups
$chmodg=rwx student
Assigns absolute permission for groups of all read, write and execute permissions

wc–it counts the number of lines, words, character in a specified file(s) with the options as –l,-w,-c
Syn: $wc –l filename
$wc –w filename
$wc–c filename

Operation Permission

u– users g–group o– +assign r– read w– write x-


others -remove execute
=assign absolutely

BASICS OF UNIX COMMANDS


UNIX EDITORS

AIM:
To study of various UNIX editors such as vi, ed, ex and EMACS.
CONCEPT:
DEPT OF ISE 10
MVJ22IS32-OPERATING SYSTEMS LAB

Editor is a program that allows user to see a portion a file on the screen and modify characters and lines by
simply typing at the current position. UNIX supports variety of Editors. They are: vi, ed,ex,EMACS
Vi- vi is stands for “visual”.vi is the most important and powerful editor.vi is a full screen editor that allows
user to view and edit entire document at the same time.vi editor was written in the University of California, at
Berkley by Bill Joy, who is one of the co-founder of Sun Microsystems.

Features of vi:
It is easy to learn and has more powerful features.
It works greats peed and is case sensitive. Vi has powerful undo functions and has 3modes:
 Command mode
 Insert mode
 Escape or ex mode
In command mode, no text is displayed on the screen.
In Insert mode, it permits user to edit insert or replace text. In escape mode, it displays commands at command
line.
Moving the cursor with the help of h, l, k, j, I, etc

EMACS Editor
Motion Commands:
M-> Move to end of file
M-< Move to beginning of file
C-v Move forward a screen M –v Move backward a screen C –n Move to next line C-p Move to previous line
C-a Move to the beginning of the line C-e Move to the end of the line
C-f Move forward a character C-b Move backward a character M-f Move forward a word
M-b Move backward a word

Deletion Commands:
DEL delete the previous character C -d delete the current character M -DEL delete the previous word
M-d delete the next word
C-x DEL deletes the previous sentence
M-k delete the rest of the current sentence
C-k deletes the rest of the current line
C-xuundo the lasted it change
Search and Replace in EMACS:
yChange the occurrence of the pattern
nDon‟tchange the occurrence, but look for the other q
Don‟t change. Leave query replace completely
!Change this occurrence and all others in the file
DEPT OF ISE 11
MVJ22IS32-OPERATING SYSTEMS LAB

1.Develop a c program to implement the Process system calls(fork(),exec(),wait(),create process, terminate


process)

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

main(void) {
pid_tpid = 0;

DEPT OF ISE 12
MVJ22IS32-OPERATING SYSTEMS LAB

pid = fork();
if (pid == 0) {
printf("I am the child.\\n");
}
if (pid> 0) {
printf("I am the parent, the child is %d.\\n", pid);
}
if (pid< 0) {
perror("In fork():");
}

exit(0);
}

2. Simulate the following CPU scheduling algorithms to find turnaround time and waiting time

a) FCFS b) SJF c) Round Robin d)Priority.

#include<std
io.h>#includ
e<conio.h>m
ain()
DEPT OF ISE 13
MVJ22IS32-OPERATING SYSTEMS LAB

{
Int
bt[20],wt[20],tat[20],i,n;f
lot wtavg,tatavg;
clrscr();
printf ("\n Enter the number of processes
");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for Process %d--",i);
scanf("%d",&bt[i]);
}
wt[0]=wtavg=0;
tat[0]=tatavg=
bt[0];
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=tat[i-1]+bt[i];
wtavg=wtavg+wt[i]
;
tata=tatavg+ tat[i];
}
printf ("\t PROCESS \tBURST TIME\tWAITING TIME\tTURN AROUNDTIME\n");
for(i=0;i<n;i++)
printf("\n\tP%d\t\t%d\t\t%d\t\t%d",i,bt[i],wt[i],tat[i]);
printf("\nAverage Waiting Time--%f",wt avg/n);
printf("\nAverage TurnaroundTime%f",tatavg/n);
getch();
}

INPUT
Enter the number of processes-- 3
DEPT OF ISE 14
MVJ22IS32-OPERATING SYSTEMS LAB

Enter Burst Time for Process0-- 24


Enter Burst Time for Process1 -- 3
Enter Burst Time for Process2-- 3

OUTPUT
PROCESS BURSTTIME WAITINGTIME TURNAROUNDTIME

P0 24 0 24
P1 3 24 27
P2 3 27 30
Average Waiting Time-- 17.000000
Average Turnaround Time-- 27.000000

SOURCE CODE :

#include<std
io.h>#includ
e<conio.h>m
ain()
{
intp[20],bt[20],wt[20],tat[20],i,k,n,temp;floatwtavg,tatavg;
clrscr();
printf("\nEnter the number of processes
-- ");scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i]=i;
printf("Enter Burst Time for Process %d
-- ", i);
scanf("%d",&bt[i]);

for(i=0;i<n;i++)

DEPT OF ISE 15
MVJ22IS32-OPERATING SYSTEMS LAB

for(k=i+1;k<n;k
++)
if(bt[i]>bt[k])
{
temp
=bt[i]
;bt[i]
=bt[k]
;bt[k]
=temp
;

temp
=p[i];
p[i]=
p[k];
p[k]=
temp;
}
wt[0]=wtavg=0;
tat[0] =tat avg =bt[0];
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=tat[i-
1]+bt[i];
wtavg=wtavg+wt[i
];
tatavg =tatavg+
tat[i];
}
printf("\n\tPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");
for(i=0;i<n;i++)

DEPT OF ISE 16
MVJ22IS32-OPERATING SYSTEMS LAB

printf("\n\t P%d \t\t %d \t\t %d \t\t %d", p[i], bt[i], wt[i],


tat[i]);
printf("\nAverageWaitingTime--%f",wtavg/n);
printf("\nAverageTurnaroundTime --%f", tatavg/n);
getch();
}

DEPT OF ISE 17
MVJ22IS32-OPERATING SYSTEMS LAB

INPUT
Enterthenumberofprocesses-- 4
EnterBurstTimeforProcess0-- 6
EnterBurstTimeforProcess1-- 8
EnterBurstTimeforProcess2-- 7
EnterBurstTimeforProcess3-- 3
OUTPUT
PROCESS BURST WAITING TURNARO
TIME TIME UNDTIME
P3 3 0 3
P0 6 3 9
P2 7 9 16
P1 8 16 24
AverageWaitingTime -- 7.000000
AverageTurnaroundTime-- 13.000000

18
MVJ22IS32-OPERATING SYSTEMS LAB

SOURCECODE
#include<stdio.h>
main()
{
Int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
Float awt=0,att=0,temp=0;
clrscr();
printf("Enterthenoofprocesses--");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for process%d--",i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnter the size of time slice--");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])
max=bu[i];
for(j=0;j<(max/t)+1;j+
+)for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t)
{
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
Else
{
bu[i]=bu[i]-t;

19
MVJ22IS32-OPERATING SYSTEMS LAB

temp=temp+t
;
}
for(i=0;i<n;i++)
{
wa[i]=tat[i]-ct[i];
att+=tat[i];
awt+=wa[i];
}
printf("\nTheAverageTurnaroundtimeis--%f",att/n);
printf("\nTheAverageWaitingtimeis--%f",awt/n);
printf("\n\tPROCESS\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME\n");
for(i=0;i<n;i++)
printf("\t%d\t%d\t\t%d\t\t%d\n",i+1,ct[i],wa[i],tat[i]);
getch();
}

OUTPUT:

OUTPUT:
PROCESS BURSTTIME WAITINGTIME TURNAROUNDTIME
1 24 6 30
2 3 4 7
3 3 7 10
The Average Turn around time is–15.666667
The Average Waiting time is-------5.666667

20
MVJ22IS32-OPERATING SYSTEMS LAB

SOURCECODE:

#include<stdio.h>
main()
{
intp[20],bt[20],pri[20],wt[20],tat[20],i,k,n,temp;
Float wt avg,tat avg;
clrscr();
printf("Enterthenumberofprocesses---");scanf("%d",&n
);
for(i=0;i<n;i++)
{p[i]= i;
printf("Enter the Burst Time & Priority of Process %d---",i);
scanf("%d%d",&bt[i],&pri[i]);
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k+
+)if(pri[i] >pri[k])
{
temp=p[i];p[i]=p[k]
;p[k]=temp;
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;
}
wtavg=wt[0]=0;
tatavg = tat[0] = bt[0];
for(i=1;i<n;i++)
21
MVJ22IS32-OPERATING SYSTEMS LAB

{
wt[i]=wt[i-1] +bt[i-1];
tat[i] =tat[i-1]+bt[i];

wtavg=wtavg+wt[i];
tatavg =tatavg+ tat[i];
}
printf("\nPROCESS\t\tPRIORITY\tBURSTTIME\tWAITINGTIME\tTURNAROUNDTIME");
for(i=0;i<n;i++)
printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ",p[i],pri[i],bt[i],wt[i],tat[i]);
printf("\nAverageWaitingTimeis---%f",wtavg/n); printf("\
nAverageTurnaroundTimeis---%f",tatavg/n);
getch();
}

INPUT
Enter the number of processes– 53
Enter the Burst Time &Priority of Process 0---10
Enter the Burst Time & Priority of Process 1---1 1
Enter the Burst Time & Priority of Process 2---2 4
Enter the Burst Time & Priority of Process 3---1 5
Enter the Burst Time & Priority of Process 4---5 2
OUTPUT
PROCESS PRIORITY BURSTTIME WAITING TURNAROUND
TIME 0 TIME1
1 1 1
4 2 5 1 6
0 3 10 6 16
2 4 2 16 18
3 5 1 18 19
Average Waiting Time is--- 8.200000
Average Turn around Time is----------------12.000000

22
MVJ22IS32-OPERATING SYSTEMS LAB

3. Develop a C program to simulate producer-consumer problem using semaphores.

#include<stdio.>
voidmain()
{
Int buffer[10],bufsize,in,out,produce,consume,choice=0;
in=0;
out=0;
bufsize=10;
while(choice!=3)
{
printf(“\n1. Produce \t 2. Consume \t3.
Exit”);printf(“\nEnteryourchoice:”);
scanf(“%d”,&choice);
switch(choice){
case1:if((in+1)%bufsize==out)
printf(“\nBufferisFull”);

else
{
printf(“\
nEnterthevalue:“);scanf(“%
d”,&produce);buffer[in]=
produce;
} in=(in+1)%bufsize;
break;;;
case2: if(in==out)
printf(“\nBufferisEmpty”);
{

} } consume=buffer[out];

} printf(“\nThe consumed value is %d”, consume);

else out = (out+1)%bufsize;


}}
23
MVJ22IS32-OPERATING SYSTEMS LAB

break;

24
MVJ22IS32-OPERATING SYSTEMS LAB

OUTPUT
1.Produce 2.Consume 3.Exit
Enter your choice:2
Buffer is Empty
1.Produce 2.Consume 3.Exit
Enter your choice:1
Enter the value:100
1.Produce 2.Consume 3.Exit
Enter your choice:2
The consumed value is 100
1.Produce 2.Consume 3.Exit
Enter your choice:3

25
MVJ22IS32-OPERATING SYSTEMS LAB

4.Develop aC program which demonstrates inter process communication between a reader


process and a writer process. Use mkfifo,open, read,write and close APIs in your program.

/*WriterProcess*/

#include
<stdio.h>#include
<fcntl.h>#include
<sys/stat.h>#include
<sys/types.h>#include
<unistd.h>

Int main()
{
int fd;
char buf[1024];

/* create the FIFO (named pipe)


*/char * myfifo = "/tmp/myfifo";
mkfifo(myfifo, 0666);
printf("Run Reader process to read the FIFO File\n");
fd=open(my fifo, O_WRONLY);
write(fd,"Hi",sizeof("Hi"));

/*write"Hi"to the
FIFO*/close(fd);
unlink(myfifo); /* remove the FIFO */
return 0;
}

26
MVJ22IS32-OPERATING SYSTEMS LAB

/*ReaderProcess*/
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include<unistd.h>
#include<stdio.h>
#define MAX_BUF 1024int main()
{

int fd;

/*AtempFIFOfileis notcreatedin reader*/char *myfifo = "/tmp/myfifo";


charbuf[MAX_BUF];

/* open, read, and display the message from the FIFO */

fd=open(my fifo, O_RDONLY);


read(fd, buf, MAX_BUF);
printf("Writer:%s\n",buf);
close(fd);
return 0;

27
MVJ22IS32-OPERATING SYSTEMS LAB

5. Develop a C program to simulate Bankers Algorithm for Dead Lock Avoidance.

#include<stdio.h>
#include<conio.h>
voidmain()
{
charjob[10][10];
inttime[10],avail,tem[10],temp[10];
Int safe[10];
Int ind=1,i,j,q,n,t;
clrscr();
printf("Enter no of jobs:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter name and time: ");
scanf("%s%d",&job[i],&time[i]);
}
printf("Enter the available resources:");
scanf("%d",& avail);
for(i=0;i<n;i++)
{
temp[i]=time[i];
tem[i]=i;
}
for(i=0;i<n;i+
+)for(j=i+1;j<n;j+
+)
{
if(temp[i]>temp[j])
{
t=temp[i];

28
MVJ22IS32-OPERATING SYSTEMS LAB

temp[i]=temp[j];
temp[j]=t;
t=tem[i];
tem[i]=tem[j];
tem[j]=t;
}
}
for(i=0;i<n;i++)
{
q=tem[i];
if(time[q]<=avail)
{
safe[ind]=tem[i];
avail=avail-tem[q];
printf("%s",job[safe[ind]]);
ind++;
}
else
{
printf("No safe sequence\n");
}
}
printf("Safe sequence is:");
for(i=1;i<ind;i++)
printf("%s %d\
n",job[safe[i]],time[safe[i]]);getch();
}

29
MVJ22IS32-OPERATING SYSTEMS LAB

OUTPUT:

Enter no of jobs:4
Enter name and time: A
1 Enter name and time: B
4 Enter name and time:
C2 Enter name and
time:D3
Enter the available resources: 20
Safe sequence is:A1,C2,D3,B4.

30
MVJ22IS32-OPERATING SYSTEMS LAB

7. Develop a C program to simulate the following contiguous memory allocation Techniques:

a) Worst fit b)Best fit c) First fit.

PROGRAM

WORST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25
voidmain()
{
Int frag[max],b[max],f[max],i,j,nb,nf,temp;
Static int bf [max],ff [max];
clrscr();
printf("\n\tMemory Management Scheme-First Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File%d:",i);
scanf("%d",&f[i]);

31
MVJ22IS32-OPERATING SYSTEMS LAB

}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size:\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();

INPUT

Enter the number of blocks:3


Enter the number of files: 2

Enter the size of the blocks:-


Block1:5
Block2: 2
Block3: 7

Enter the size of the files:-


32
MVJ22IS32-OPERATING SYSTEMS LAB

File 1:1
File 2:4

OUTPUT
FileNo FileSize BlockNo BlockSize Fragmen
t
1 1 1 5 4
2 4 3 7 3

33
MVJ22IS32-OPERATING SYSTEMS LAB

BEST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25
voidmain()
{
Int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
Static int bf[max],ff[max];
clrscr();
printf("\n Enter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
printf("Block%d:",i);
scanf("%d",&b[i]);
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File%d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{

DEPARTMENT OF CSE 33
MVJ22IS32-OPERATING SYSTEMS LAB

ff[i]=j;lowest=
temp;
}
}}
frag[i]=lowest;bf[ff[i]]=1;lowest=10000;
}
printf("\nFile No\tFile Size\tBlockNo\tBlockSize\tFragment");
for(i=1;i<=nf&&ff[i]!=0;i++)

printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);getch();
}

INPUT
Enter the number of blocks:3
Enter the number of files: 2

Enter the size of the blocks:-


Block1:5
Block2: 2
Block3: 7

Enter the size of the files:-


File 1:1
File2:4

OUTPUT
FileNo FileSize Block No Block Size Fragment
1 1 2 2 1
2 4 1 5 1

DEPARTMENT OF CSE 33
MVJ22IS32-OPERATING SYSTEMS LAB

FIRST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25
voidmain()
{
Int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
Static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme-Worst Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number offiles:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block%d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File%d:",i);
scanf("%d",&f[i]);
}

DEPARTMENT OF CSE 33
MVJ22IS32-OPERATING SYSTEMS LAB

for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)//if bf[j] is not allocated
{
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
{
}
}
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
}
ff[i]=j;
highest=temp;
}
printf("\nFile_no:\tFile_size:\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);getch();
}

INPUT

Enter the number of blocks:3


Enter the number offiles: 2

Enter the size of the


blocks:-

Block1:5
Block2: 2
Block3: 7

37
MVJ22IS32-OPERATING SYSTEMS LAB

Enter the size of the files:-


File 1:1
File2:4

OUTPUT
FileNo FileSize Block No Block Size Fragment
1 1 3 7 6
2 4 1 5 1

38
MVJ22IS32-OPERATING SYSTEMS LAB

8. Develop a C program to simulate page replacement algorithms:

a) FIFO b) LRU

FIRST IN FIRST OUTS

SOURCECODE :

#include<stdio.h>

#include<conio.h>

int fr[3];

Void main()
{
Void display();
Int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};
Int flag1=0,flag2=0,pf=0,frsize=3,top=0;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0;flag2=0;
for(i=0;i<12;i++)
{
if(fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}

39
MVJ22IS32-OPERATING SYSTEMS LAB

}
if(flag1==0)
{
for(i=0;i<frsize;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
fr[top]=page[j];
top++;
pf++;
if(top>=frsize)
top=0;
}
display();
}

printf("Number of page faults:%d",pf+frsize);

getch();
}
Void display()
{
Int i;
printf("\n");
for(i=0;i<3;i++)
printf("%d\t",fr[i]);

40
MVJ22IS32-OPERATING SYSTEMS LAB

OUTPUT:

2-1-1
23-1
23-1
231
531
521
524
524
324
324
354
352

Number of page faults: 9

41
MVJ22IS32-OPERATING SYSTEMS LAB

LRU

SOURCECODE:

#include<stdio.h>
#include<conio.h>
int fr[3];
Void main()
{
Void display();
Int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3];
Int
index,k,l,flag1=0,flag2=0,pf=0,frsize=3;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0,flag2=0;
for(i=0;i<3;i++)
{
if(fr[i]==p[j])
{
flag1=1;flag2=
1;
break;
}
}
if(flag1==0)

42
MVJ22IS32-OPERATING SYSTEMS LAB

{
for(i=0;i<3;i++)
{
if(fr[i]==-1)
{
fr[i]=p[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<3;i+
+)fs[i]=0;
for(k=j-1,l=1;l<=frsize-1;l++,k--)
{
for(i=0;i<3;i++)
{
if(fr[i]==p[k])fs[i]=1;
}}
for(i=0;i<3;i++)
{
if(fs[i]==0)
index=i;
}
fr[index]=p[j];
pf++;
}
display();
}
printf("\nnoofpagefaults:%d",pf+frsize);

43
MVJ22IS32-OPERATING SYSTEMS LAB

getch();
}

Void display()
{
Int i;
printf("\n");
for(i=0;i<3;i++)
printf("\t%d",fr[i]);
}

OUTPUT:
2-1-1
23-1
23-1
231
251
251
254
254
354
352
352
352

No of page faults:7

44
MVJ22IS32-OPERATING SYSTEMS LAB

8.Simulate following File Organization Techniques


a) Single level directory b)Two level directory
SOURCECODE :
#include<stdio.h>
struct
{
char dname[10],fname[10]
[10];int fcnt;
}
dir;

voidmain()
{
Int i,ch;
char f[30];
clrscr();
dir.fcnt= 0;
printf("\nEnter name of directory -- ");
scanf("%s",dir.dname);
while(1)
{
printf("\n\n1.CreateFile\t2.DeleteFile\t3.SearchFile \n
4. Display Files\t5. Exit\nEnter your choice -- ");
scanf("%d",&ch);
switch(ch)
{
case1:
printf("\nEnter the name of the file--");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
case 2:
printf("\nEnter the name of the file -- ");
45
MVJ22IS32-OPERATING SYSTEMS LAB

scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f,dir.fname[i])==0)
{
printf("File%s isdeleted",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
}

46
MVJ22IS32-OPERATING SYSTEMS LAB

}
if(i==dir.fcnt)
printf("File%snotfound",f);

else

dir.fcnt--;
break;

case3: printf("\nEnter the name of the file--");

scanf("%s",f);

for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f,dir.fname[i])==0)
{
printf("File %s isfound",f);
break;
}
}
if(i==dir.fcnt)
printf("File%s no found",f);
break;
case4: if(dir.fcnt==0)
printf("\nDirectory Empty");
else
{
printf("\nThe Files are -- ");
for(i=0;i<dir.fcnt;i++)
printf("\t %s",dir.fname[i]);
}
break;

47
MVJ22IS32-OPERATING SYSTEMS LAB

}
getch();
}
default:exit(0);
}

OUTPUT:

Enter name of directory--CSE


1. Create File 2. Delet File 3. Search File
4. Display Files 5.Exit
Enter your choice–1

Enter the name of the file--A


1. CreateFile2. DeleteFile3. SearchFile
4. Display Files 5.Exit
Enteryourchoice–1

Enter the name of the file--B


1. Create File2. DeleteFile3. SearchFile
4. Display Files5.Exit
Enter your choice–1

Enter the name of the file--C


1. Create File 2. Delete File 3. Search File
4. Display Files 5.Exit Enter your choice–4

The Files are--ABC


1. Create File2. Delete File3. Search File
4. Display Files5.Exit
Enter your choice–3

Enter the name of the file–ABC File


ABC not found
1. Create File2. Delete File3. Search File
4. Display Files5. Exit
Enter your choice–2

Enter the name of the file–B


File B is deleted
1. Create File 2.Delete File 3.Search File
4. Display Files 5.Exit
Enter your choice–5

48
MVJ22IS32-OPERATING SYSTEMS LAB

TWO LEVEL DIRECTORY

SOURCECODE :

#include<stdio.h>
struct
{
char dname[10],fname[10]
[10];intfcnt;
}dir[10];

voidmain()
{
Int i,ch,dcnt,k;
charf[30], d[30];
clrscr();
dcnt=0;
while(1)
{
printf("\n\n1.Create Directory\t2.CreateFile\t3.DeleteFile");
printf("\n4.SearchFile\t\t5.Display\t6.Exit\tEnteryour choice--");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter name of directory -- ");
scanf("%s",dir[dcnt].dname);dir[dcnt].fcnt=0;
dcnt++;
printf("Directorycreated");break;
case2:
printf("\nEnter name of the directory--");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter name of the file--");
scanf("%s",dir[i].fname[dir[i].fcnt]);

49
MVJ22IS32-OPERATING SYSTEMS LAB

dir[i].fcnt++;
printf("File created");
}
if(i==dcnt)
printf("Directory %s notfound",d);
break;
case3:printf("\nEnter name of the directory--");
scanf("%s",d);
for(i=0;i<dcnt;i++)
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter name of the
file--");scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{
if(strcmp(f,dir[i].fname[k])==0)
{
printf("File%s is deleted",f);
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
Goto jmp;
}
}

printf("File%s not found",f);


gotojmp;
}
}
printf("Directory%s not found",d);
jmp:break;
Case 4:printf("\nEnter name of thedirectory--");
scanf("%s",d);
for(i=0;i<dcnt;i++)
{
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter the name of the file--");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{
if(strcmp(f,dir[i].fname[k])==0)
{
printf("File%s is found",f);
MVJ22IS32-OPERATING SYSTEMS LAB

gotojmp1;
}
}
printf("File%snotfound",f);
gotojmp1; Page44
}
}
MVJ22IS32-OPERATING SYSTEMS LAB

printf("Directory%snotfound",d);
jmp1:break;case 5:if(dcnt==0)
printf("\nNoDirectory's");
else
{
printf("\nDirectory\
tFiles");for(i=0;i<dcnt;i++)
{
printf("\n%s\t\t",dir[i].dname);for(k=0;k<dir[i].fcnt;k+
+)printf("\t%s",dir[i].fname[k]);

}
}
break;

default:exit(0);
} }
getch();
}

Page 55
MVJ22IS32-OPERATING SYSTEMS LAB

OUTPUT

1.Create Directory 2.Create File 3.DeletebFile


4.Search File 5.Display 6.Exit
Enter your choice--1
Enter name of directory--DIR1Directory created
1.Create Directory 2.Create File 3.Delete File
4. Search File 5. Display 6. Exit
Enter your choice -- 1
Enter name of directory--DIR2 Directory created
1.Create Directory 2.Create File 3.Delete File
4. Search File 5. Display 6. Exit
Enter your choice -- 2
Enter name of the directory–DIR1
Enter name of the file --
A1File created
1.Create Directory 2.Create File 3.Delete File
4.Search File5. Display 6.Exit
Enteryourchoice--2
Enter name of the directory–DIR1

Enter name of the file--A2


File created
1.Create Directory 2.CreateFile 3.DeleteFile
4.SearchFile 5.Display
6.Exit
Enter your choice–6

Page 55
MVJ22IS32-OPERATING SYSTEMS LAB

9. Develop a C program to simulate the Linked file allocation strategies.

SOURCECODE :
#include<stdio.h>
main()
{
intf[50],p,i,j,k,a,st,len,n,c;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("Enter how many blocks that are already
allocated");
scanf("%d",&p);
printf("\nEnter the blocks no. That are already allocated");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("Enter the starting index block
&length"); scanf("%d
%d",&st,&len); k=len;
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;
}
}
printf("\nIf
U
Want to enter one more file?
(yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto
X;

Page 55
MVJ22IS32-OPERATING SYSTEMS LAB

elseex
it();
getch( );
}

OUTPUT:

Enter how many blocks that are already allocated 3Enter the blocks no.s that
are already allocated 47
Enter The starting index block & length 379
3->1
4->1file is alread y
allocated 5->1
6->1
7->1 file is already
allocated 8->1
9->1 file is already
allocated
10->1
11->1
12->1

Page 55
MVJ22IS32-OPERATING SYSTEMS LAB

10. Develop a C program to simulate SCAN disk scheduling algorithm.

#include<stdio.h>
main()
{
Int t[20],d[20], h, i, j, n,temp, k,
atr[20],tot,p,sum=0;clrscr();
printf("enter the no of tracks to be traveresed");
scanf("%d'",&n);
printf("enter The Position Of head");
scanf("%d",&h);
t[0]=0;t[1]=h;
printf("enter the tracks");
for(i=2;i<n+2;i++)
scanf("%d",&t[i])
;for(i=0;i<n+2;i++)
{
for(j=0;j<(n+2)-i-1;j++)
{
if(t[j]>t[j+1])
{
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}}}
for(i=0;i<n+2;i++)
if(t[i]==h)
j=i;
k=i;
p=0;
while(t[j]!=0)
{
atr[p]=t[j];
j--;
p++;
}
atr[p]=t[j];
for(p=k+1;p<n+2;p++,k++)
atr[p]=t[k+1];
for(j=0;j<n+1;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else

Page 55
MVJ22IS32-OPERATING SYSTEMS LAB

d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("\nAverage header
movements:%f",(float)sum/n);
getch();
}

INPUT

Enter no.of tracks : 9


Enter track position:55 58 60 70 18 90 150 160 184

OUTPUT
Tracks traversed Difference between tracks

150 50
160 10
184 24
90 94
70 20
60 10
58 2
55 3
18 37

Average header movements: 27.77

Page 55
MVJ22IS32-OPERATING SYSTEMS LAB

Page 55

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy