1 DISTRIBUTED OPERATING SYSTEMS LAB MANUAL Year : 2016 - 2017 Course Code : BCS102 Regulations : IARE - R16 Semester : II Branch : CSE Prepared By Dr. K. Rajendra Prasad,Professor Mr. P. Anjaiah,Assistant Professor Department of Computer Science & Engineering INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal – 500 043, Hyderabad
49
Embed
DISTRIBUTED OPERATING SYSTEMS LAB MANUAL · II. Exposure on usage of various operating systems. III. Design modern distributed system components. LIST OF EXPERIMENTS Week-1 CPU SCHEDULING
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
DISTRIBUTED OPERATING SYSTEMS
LAB MANUAL
Year : 2016 - 2017
Course Code : BCS102
Regulations : IARE - R16
Semester : II
Branch : CSE
Prepared By
Dr. K. Rajendra Prasad,Professor
Mr. P. Anjaiah,Assistant Professor
Department of Computer Science & Engineering
INSTITUTE OF AERONAUTICAL ENGINEERING
Dundigal – 500 043, Hyderabad
2
VISION AND MISSION OF THE DEPARTMENT
VISION
The Vision of the department is to produce competent graduates suitable for industries and
organizations at global level including research and development with Social responsibility.
MISSION
To provide an open environment to foster professional and personal growth with a strong
theoretical and practical background having an emphasis on hardware and software
development making the graduates industry ready with social ethics.
Further the Department is to provide training and to partner with Global entities in education
and research.
3
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous)
DUNDIGAL – 500 043, HYDERABAD
COMPUTER SCIENCE AND ENGINEERING
M.TECH-PROGRAM OUTCOMES(POS)
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 principles of mathematics,
natural sciences, 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 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.
PO5 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.
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 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.
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 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.
PO12 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
Outcomes PSO1 Professional Skills: The ability to research, understand and implement computer programs in
the areas related to algorithms, system software, multimedia, web design, big data analytics,
and networking for efficient analysis and design of computer-based systems of varying
complexity.
4
PSO2 Problem-Solving Skills: The ability to apply standard practices and strategies in software
project development using open-ended programming environments to deliver a quality product
for business success.
PSO3 Successful Career and Entrepreneurship: The ability to employ modern computer
languages, environments, and platforms in creating innovative career paths, to be an
entrepreneur, and a zest for higher studies.
5
OBJECTIVES OF THE DEPARTMENT
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Program Educational Objectives (PEOs)
A Post Graduate of the Computer Science and Engineering Program should:
PEO – I Students will establish themselves as effective professionals by solving real problems
through the use of computer science knowledge and with attention to team work, effective
communication, critical thinking and problem solving skills.
PEO–II Students will develop professional skills that prepare them for immediate employment and
for life-long learning in advanced areas of computer science and related fields.
PEO– III Students will demonstrate their ability to adapt to a rapidly changing environment by having
learned and applied new skills and new technologies.
PEO– IV Students will be provided with an educational foundation that prepares them for excellence,
leadership roles along diverse career paths with encouragement to professional ethics and
active participation needed for a successful career.
Program Specific Outcomes (PSO's)
PSO – I Professional Skills: The ability to understand, analyze and develop computer programs in
the areas related to algorithms, system software, multimedia, web design, big data analytics,
and networking for efficient design of computer-based systems of varying complexity.
PSO – II Problem-Solving Skills: The ability to apply standard practices and strategies in software
project development using open-ended programming environments to deliver a quality
product for business success.
PSO – III Successful Career and Entrepreneurship: The ability to employ modern computer
languages, environments, and platforms in creating innovative career paths to be an
entrepreneur, and a zest for higher studies.
6
Attainment of Program Outcomes and Program Specific Outcomes
S.No Experiment
Program
Outcomes
Attained
Program Specific
Outcomes Attained
1
Simulate the following CPU scheduling
algorithms
a) Round Robin b) SJF c) FCFS d) Priority
PO1,PO5 PSO1
2
Simulate all file allocation strategies
a) Sequential b) Indexed c) Linked PO2, PO5 PSO1
3 Implement process strategies: creation of child,
zombie, orphan process PO1,PO6 PSO1
4 Implement file organization strategies
a) single level b) Two level c) Hierarchical PO1,PO6 PSO1
5 Simulate Bankers Algorithm for Dead Lock
Avoidance PO3,PO7 PSO3
6 Simulate Bankers Algorithm for Dead Lock
Prevention PO6,PO8 PSO1, PSO2
7 Simulate all page replacement algorithms
a) FIFO b) LRU c) LFU PO5,PO8 PSO1, PSO2
8 Implement shared memory and semaphore
concepts for inter process communication PO6,PO7 PSO1,PSO3
Mapping Course Objectives Leading To the Achievement of Program
Course Code Category Hours / Week Credits Maximum Marks
BCS102 Core
L T P C CIA SEE Total
-
-
3 2 30 70 100
Contact Classes: Nil Total Tutorials: Nil Total Practical Classes: 36 Total Classes: 36
OBJECTIVES:
The course should enable the students to:
I. Understand the design aspects of operating system.
II. Exposure on usage of various operating systems.
III. Design modern distributed system components.
LIST OF EXPERIMENTS
Week-1 CPU SCHEDULING ALGORITHMS
Simulate the following CPU scheduling algorithms
a) Round Robin b) SJF c) FCFS d) Priority
Week-2 FILE ALLOCATION STRATEGIES
Simulate all file allocation strategies
a) Sequential b) Indexed c) Linked
Week-3 PROCESS MANAGEMENT
Implement process strategies: creation of child, zombie, orphan process
Week-4 FILE ORGANIZATION STRATEGIES
Implement file organization strategies
a) single level b) Two level c) Hierarchical
Week-5 DEAD LOCK AVOIDANCE
Simulate Bankers Algorithm for Dead Lock Avoidance
Week-6 DEAD LOCK PREVENTION
Simulate Bankers Algorithm for Dead Lock Prevention
Week-7 PAGE REPLACEMENT ALGORITHMS
Simulate all page replacement algorithms
a) FIFO b) LRU c) LFU
33 | P a g e
8
Week-8 SHARED MEMORY AND SEMAPHORE
Implement shared memory and semaphore concepts for inter process communication Reference Books:
Andrew S. Tanenbaum, “Distributed Operating System”, PHI, 1st Edition, 1994. Web References: 1. www.cs.put.poznan.pl/pawelw/sus/dcs07.doc 2. https://developer.apple.com/library/mac/documentation
SOFTWARE AND HARDWARE REQUIREMENTS FOR 18 STUDENTS: SOFTWARE: Turbo C/ J2SE HARDWARE: 18 numbers of Intel Desktop Computers with 2 GB RAM
9
INDEX
S.No List of Experiments Page No
1 Simulate the following CPU scheduling algorithms
a) Round Robin b) SJF c) FCFS d) Priority 10-15
2
Simulate all file allocation strategies a) Sequential b) Indexed c) Linked
16-20
3 Implement process strategies: creation of child,
zombie, orphan process 21-23
4 Implement file organization strategies
a) single level b) Two level c) Hierarchical 24-38
5 Simulate Bankers Algorithm for Dead Lock Avoidance 39-42
6 Simulate Bankers Algorithm for Dead Lock Prevention 43-48
7 Simulate all page replacement algorithms
a) FIFO b) LRU c) LFU 49
10
EXPERIMENTS
1 A) ROUND ROBIN CPU SCHEDULING ALGORITHM
For round robin scheduling algorithm, read the number of processes/jobs in the system, their
CPU burst times, and the size of the time slice. Time slices are assigned to each process in
equal portions and in circular order, handling all processes execution. This allows every
process to get an equal chance. Calculate the waiting time and turnaround time of each of the
processes accordingly
PROGRAM
A) ROUND ROBIN CPU SCHEDULING ALGORITHM
#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("Enter the no of processes -- "); 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; temp=temp+t;
} for(i=0;i<n; i++) { wa[i]=tat[i]-ct[i];
att+=tat[i];
awt+=wa[i];
11
}
printf("\nThe Average Turnaround time is -- %f",att/n);
printf("\nThe Average Waiting time is -- %f ",awt/n);
printf("\n\tPROCESS\t BURST TIME \t WAITING TIME\tTURNAROUND TIME\n");
printf("\nEnter the file name to be searched -- ");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s, ft[i].name)==0)
break;
if(i==n)
printf("\nFile Not Found");
else
{
printf("\nFILE NAME NO OF BLOCKS BLOCKS OCCUPIED");
printf("\n %s\t\t%d\t",ft[i].name,ft[i].nob);
temp=ft[i].sb;
for(j=0;j<ft[i].nob;j++)
{
printf("%d ",temp->bno); temp = temp->next;
}
}
getch();
}
INPUT:
Enter no of files : 2
Enter file 1 : A
Enter no of blocks in file 1: 4
Enter the blocks of the file 1: 12 23 9 4
Enter file 2 : G
Enter no of blocks in file 2: 5
Enter the blocks of the file 2: 88 77 66 55 44
Enter the file to be searched : G
OUTPUT:
FILE NAME NO OF BLOCKS BLOCKS OCCUPIED
G 5 88
77
66
55
44
21
3. Program to implement process strategies: creation of child, zombie and orphan process
#include<stdio.h> main() { int id; printf("Before fork()\n"); id=fork(); if(id==0) { printf("Child has started: %d\n ",getpid()); printf("Parent of this child : %d\n",getppid()); printf("child prints 1 item :\n "); sleep(10); printf("child prints 2 item :\n"); } else { printf("Parent has started: %d\n",getpid()); printf("Parent of the parent proc : %d\n",getppid()); } printf("After fork()"); } OUTPUT
*********** [04mca58@LINTEL 04mca58]$ cc orphan.c [04mca58@LINTEL 04mca58]$ ./a.out Before fork() Parent has started: 2899 Child has started: 2900 Parent of this child : 2899 child prints 1 item : Parent of the parent proc : 616 After fork() [04mca58@LINTEL 04mca58]$ child prints 2 item : After fork()
PROGRAM FOR ZOMBIE PROCESS
#include<stdio.h> main() { int id; id=fork(); if(id>0) { printf("Parent will sleep"); sleep(10); }
22
if(id==0) printf("I am child"); } OUTPUT *********** [04mca58@LINTEL 04mca58]$ cc zombie.c [04mca58@LINTEL 04mca58]$ ./a.out I am child Parent will sleep [04mca58@LINTEL 04mca58]$ //same program different code #include<stdio.h> #include<unistd.h> #include<stdlib.h> int main() { int pid; pid=fork(); if(pid<0) { printf("\n Error "); exit(1); } else if(pid==0) { printf("\n Hello I am the child process "); printf("\n My pid is %d ",getpid()); exit(0); } else { printf("\n Hello I am the parent process "); printf("\n My actual pid is %d \n ",getpid()); exit(1); } } I tried this , I hope its correct . But I am not satisfied with the output . The output is : Hello I am the parent process My actual pid is 4287 ashu@ashu-VirtualWorld:~/Desktop/4thSemester/testprep$ Hello I am the child process My pid is 4288
23
#include<stdio.h> #include<unistd.h> #include<stdlib.h> #include<sys/wait.h> int main() { int status; int pid; pid=fork(); if(pid<0) { printf("\n Error "); exit(1); } else if(pid==0) { printf("\n Hello I am the child process "); printf("\n My pid is %d ",getpid()); exit(0); } else { wait(&status); printf("\n Hello I am the parent process "); printf("\n My actual pid is %d \n ",getpid()); exit(1); } }
24
4. Write a C program to simulate the following file organization techniques
a) Single level directory
b) Two level directory
c) Hierarchical
DESCRIPTION:
The directory structure is the organization of files into a hierarchy of folders. In a single-level
directory system, all the files are placed in one directory. There is a root directory which has all
files. It has a simple architecture and there are no sub directories. Advantage of single level
directory system is that it is easy to find a file in the directory. In the two-level directory system,
each user has own user file directory (UFD). The system maintains a master block that has one
entry for each user. This master block contains the addresses of the directory of the users. When
a user job starts or a user logs in, the system's master file directory (MFD) is searched. When a
user refers to a particular file, only his own UFD is searched. This effectively solves the name
collision problem and isolates users from one another. Hierarchical directory structure allows
users to create their own subdirectories and to organize their files accordingly. A tree is the most
common directory structure. The tree has a root directory, and every file in the system has a
unique path name. A directory (or subdirectory) contains a set of files or subdirectories.
5. BANKERS ALGORITHM FOR THE PURPOSE OF DEADLOCK AVOIDANCE.
In a multiprogramming environment, several processes may compete for a finite number
of resources. A process requests resources; if the resources are not available at that time,
the process enters a waiting state. Sometimes, a waiting process is never again able to
change state, because the resources it has requested are held by other waiting processes.
This situation is called a deadlock. Deadlock avoidance is one of the techniques for
handling deadlocks. This approach requires that the operating system be given in advance
additional information concerning which resources a process will request and use during
its lifetime. With this additional knowledge, it can decide for each request whether or not
the process should wait. To decide whether the current request can be satisfied or must be
delayed, the system must consider the resources currently available, the resources
currently allocated to each process, and the future requests and releases of each process.
Banker’s algorithm is a deadlock avoidance algorithm that is applicable to a system with
multiple instances of each resource type.
PROGRAM #include<stdio.h> struct file
{ int all[10];
int
max[10];
int
need[10];
int flag; };
void main()
{ struct file f[10]; int fl; int i, j, k, p, b, n, r, g, cnt=0, id, newr; int avail[10],seq[10]; clrscr(); printf("Enter number of processes -- "); scanf("%d",&n); printf("Enter number of resources -- "); scanf("%d",&r); for(i=0;i<n;i++)
} printf("\nThe number of page faults using LRU are %d",pf); getch();
}
INPUT
Enter the length of reference string -- 20 Enter the reference string -- 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 Enter the number of frames -- 3 OUTPUT
The Page Replacement process is -- 7 -1 -1 PF No. -- 1