Shivaji Rao Kadam Institute of Technology & Management
Department of Computer Science & Engineering
LAB MANUAL
SUBJECT NAME---Operating Systems Lab
SUBJECT CODE---CS-405
CLASS/SECTION---CSE
YEAR/SEMESTER---SECOND YEAR / IV
Faculty Name –Ms. Priyanshu Dhameniya, Asst. Prof., CSE
Shivaji Rao Kadam Institute of Technology & Management
Department of Computer Science & Engineering
Session: Jan – June 2025
LAB MANUAL
Semester-IV
CS-405/Operating System Lab
VISION OF THE DEPARTMENT
Making our students technically superior and ethically strong, who in turn shall advance the quality of
life. To generate competent professionals to become part of the industry and research organizations at the
national and international levels.
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.Problemanalysis: Identify,formulate, 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 teamwork: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 (PSOs)
PSO -1 Foundation of mathematical concepts: To use mathematical methodologies to crack problem using
suitable mathematical analysis, data structure and suitable algorithm.
PSO - 2 Foundation of Computer System: the ability to interpret the fundamental concepts and methodology of
computer systems. Students can understand the functionality of hardware and software aspects of computer
systems.
PSO - 3 Foundations of Software development: the ability to grasp the software development lifecycle and
methodologies of software systems. Possess competent skills and knowledge of software design process.
Familiarity and practical proficiency with a broad area of programming concepts and provide new ideas and
innovations towards research.
Course Outcomes (CO)
At the end of the course, student would be able to
CO1:Students will understand the need of object oriented programming, fundamental concepts and will be
able to solve computational problems using basic constructs like if-else, control structures, array, strings in
Java environment.
CO2:Student will understand how to model the real world scenario using class diagram and be able to exhibit
communication between objects using sequence diagram..
CO3: Students will be able to implement relationships between classes..
CO4:Students will be able to demonstrate various collection classes.
CO5: Students will be able to create and user interfaces and packages
CO6:The students will be able to demonstrate programs on exceptions, multithreading and applets
INDEX
Experiments List
S.N NAME OF DATE OF REMARK
O EXPERIMENT SUBMISSION
1 WAP to implement FCFS
scheduling
2 WAP to implement SJF
scheduling
3 WAP to implement SRTF
scheduling
4 WAP to implement Priority
scheduling
5 WAP to implement RR
scheduling
6 WAP to implement
Banker’s Algorithm
7 Study of Process Life Cycle
8 Study of Deadlock and its
condition.
9 Study of RPC
10 Study of Computer Viruses
S.NO NAME OF PRACTICAL
1. Write a program to implement FCFS scheduling
2. Write a program to implement SJF scheduling
Study of RPC
3 Write a program to implement SRTF scheduling
4 Write a program to implement Priority scheduling
5 Write a program to implement RR scheduling
6 Write a program to implement Banker's Algorithm
7 Study of Process Life Cycle
8 Study of Deadlock and its condition.
9 Study of Computer Viruses
10 Study of Computer Viruses
Practical: - 1
Que-1.Write a program to implement FCFS CPU scheduling algorithm.
Solution:-
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5];
int tot=0,wt[10],i,n;
float avg=0;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
Output:-
enter no of processes: 5
enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1
p_name P_time w_time
aaa 4 0
bbb 3 4
ccc 2 7
ddd 5 9
eee 1 14
total waiting time=34
avg waiting time=6.80
Practical: - 2
Que-2. Write a program to implement SJF scheduling.
Solution:-
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5],temp[5];
int tot=0,wt[10],pt[10],i,j,n,temp1;
float avg=0;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(pt[i]>pt[j])
{
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
Output:-
enter no of processes: 5
enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1
p_name P_time w_time
eee 1 0
ccc 2 1
bbb 3 3
aaa 4 6
ddd 5 10
total waiting time=20
avg waiting time=4.00
Practical: - 3
Que-3. Write a program to implement SRTF scheduling
Solution:-
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
struct pro
{
int no;
int btime;
int atime;
int stime;
int etime;
int wtime;
int ttime;
int rtime;
}proc[100],junk;
void sort(int n)
{
pro temp;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(proc[j].atime>proc[j+1].atime)
{
temp=proc[j];
proc[j]=proc[j+1];
proc[j+1]=temp;
}
}
}
pro min(int n,int & t)
{ sort(n);
pro temp; pro mint;
for(int i=0;i<n;i++)
for(int j=0;j<n-i-1;j++)
{
if(proc[j].rtime>proc[j+1].rtime)
{
temp=proc[j];
proc[j]=proc[j+1];
proc[j+1]=temp;
}
}
int i;int flag=0;
for( i=0;i<n;i++)
{
if(proc[i].rtime>0&&proc[i].atime<=t&&flag==0)
{
cout<<"return proc id"<<proc[i].no<<endl;
return proc[i];
flag++;
}
}
for(int k=0;k<n;k++)
{
cout<<endl<<proc[k].rtime<<" remaining time of process "<<proc[k].no<<endl;
}
if(flag)
{
return mint;
}
if(proc[n-1].atime>t)
{
cout<<"no such process exists"<<endl;
junk.no=-100;
return junk;
}
}
int main()
{
junk.no=-100;
int to_time=0,n;
float avgwtime=0,avgtatime=0;
int total=0;
printf("Enter no of processes you want");
cin>>n;
if(n<=0)
{
printf("\nInvalid no of processes\n");
return 1;
}
for(int i=0;i<n;i++)
{
printf("\nEnter arrival time of process t %d\t",i+1);cin>>proc[i].atime;
printf("\nEnter burst time of process t %d\t",i+1);cin>>proc[i].btime;
proc[i].rtime=proc[i].btime;
proc[i].no=i+1; proc[i].ttime=0;
total+=proc[i].btime;
}
int t=0 ;
pro current;
int i=0;
while(t<=total)
{
if((min(n,t)).no==junk.no)
{
t++;
}
else{
current=min(n,t);
cout<<"cuurent proc id"<<current.no<<endl;
}
while(current.rtime>0&& (min(n,t)).no==(current).no)
{
current.rtime--;
for(int l=0;l<n;l++)
{ if(proc[l].no==current.no)
{
proc[l].rtime=current.rtime;
}
}
cout<<"running time of current process "<<current.no <<" is"<<current.rtime<<endl;
t++;
}
if((current).rtime==0)
{
cout<<endl<<"process over now"<<endl;
}
else
{
cout <<endl<<"process needs to be preemted"<<endl;
}
cout<<"current time is :"<<t<<endl;
if((min(n,t)).no==junk.no)
}
else{
current=min(n,t);
cout<<"cuurent proc id"<<current.no<<endl;
}
getch();
return 0;
}
Output:-
Enter no of processes you want3
Enter arrival time of process t 1 0
Enter burst time of process t 1 5
Enter arrival time of process t 2 5
Enter burst time of process t 2 5
Enter arrival time of process t 3 10
Enter burst time of process t 3 5
return proc id1
return proc id1
cuurent proc id1
return proc id1
running time of current process 1 is4
return proc id1
running time of current process 1 is3
return proc id1
running time of current process 1 is2
return proc id1
running time of current process 1 is1
return proc id1
running time of current process 1 is0
process over now
current time is :5
return proc id2
return proc id2
cuurent proc id2
return proc id2
return proc id2
cuurent proc id2
return proc id2
running time of current process 2 is4
return proc id2
running time of current process 2 is3
return proc id2
running time of current process 2 is2
return proc id2
running time of current process 2 is1
return proc id2
running time of current process 2 is0
process over now
current time is :10
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
running time of current process 2 is0
process over now
current time is :11
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
running time of current process 2 is0
process over now
current time is :12
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
running time of current process 2 is0
process over now
current time is :13
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
running time of current process 2 is0
process over now
current time is :14
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
running time of current process 2 is0
process over now
current time is :15
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
running time of current process 2 is0
process over now
current time is :16
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
0 remaining time of process 0
0 remaining time of process 1
0 remaining time of process 2
cuurent proc id2
Practical:- 4
Que-4 Write a program to implement priority scheduling
Solution:-
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i;
printf("Enter the number of process : ");
scanf("%d",&n);
printf("\n Enter process : time priorities \n");
for(i=0;i<n;i++)
{
printf("\nProcess no %d : ",i+1);
scanf("%d %d",&pt[i],&pp[i]);
p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(pp[i]<pp[j])
{
x=pp[i];
pp[i]=pp[j];
pp[j]=x;
x=pt[i];
pt[i]=pt[j];
pt[j]=x;
x=p[i];
p[i]=p[j];
p[j]=x;
}
}
}
w[0]=0;
awt=0;
t[0]=pt[0];
atat=t[0];
for(i=1;i<n;i++)
{
w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+pt[i];
atat+=t[i];
}
printf("\n\n Job \t Burst Time \t Wait Time \t Turn Around Time Priority \n");
for(i=0;i<n;i++)
printf("\n %d \t\t %d \t\t %d \t\t %d \t\t %d \n",p[i],pt[i],w[i],t[i],pp[i]);
awt/=n;
atat/=n;
printf("\n Average Wait Time : %d \n",awt);
printf("\n Average Turn Around Time : %d \n",atat);
getch();
}
Output:-
Enter process:p1
Enter cpu burst:10
Enter priroty:3
Enter process:p2
Enter cpu burst:1
Enter priroty:1
Enter process:p3
Enter cpu burst:2
Enter priroty:4
Enter process:p4
Enter cpu burst:1
Enter priroty:5
Enter process:p5
Enter cpu burst:5
Enter priroty:2
Process gaint chart is below::
0-p2-1-p5 -6- p1 -16- p3 -18- p4-19
TP:0.26
TAT:12
RT:12
WT:6.2
Practical:- 5
Que-5. Write a program to implement Round Robin.
Solution:-
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
void main()
{
char p[10][5];
int et[10],wt[10],timer=3,count,pt[10],rt,i,j,totwt=0,t,n=5,found=0,m;
float avgwt;
clrscr();
for(i=0;i<n;i++)
{
printf("enter the process name : ");
scanf("%s",&p[i]);
printf("enter the processing time : ");
scanf("%d",&pt[i]);
}
m=n;
wt[0]=0;
i=0;
do
{
if(pt[i]>timer)
{
rt=pt[i]-timer;
strcpy(p[n],p[i]);
pt[n]=rt;
et[i]=timer;
n++;
}
else
{
et[i]=pt[i];
}
i++;
wt[i]=wt[i-1]+et[i-1];
}while(i<n);
count=0;
for(i=0;i<m;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(p[i],p[j])==0)
{
count++;
found=j;
}
}
if(found!=0)
{
wt[i]=wt[found]-(count*timer);
count=0;
found=0;
}
}
for(i=0;i<m;i++)
{
totwt+=wt[i];
}
avgwt=(float)totwt/m;
for(i=0;i<m;i++)
{
printf("\n%s\t%d\t%d",p[i],pt[i],wt[i]);
}
printf("\ntotal waiting time %d\n",totwt);
printf("total avgtime %f",avgwt);
}#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
void main()
{
char p[10][5];
int et[10],wt[10],timer=3,count,pt[10],rt,i,j,totwt=0,t,n=5,found=0,m;
float avgwt;
clrscr();
for(i=0;i<n;i++)
{
printf("enter the process name : ");
scanf("%s",&p[i]);
printf("enter the processing time : ");
scanf("%d",&pt[i]);
}
m=n;
wt[0]=0;
i=0;
do
{
if(pt[i]>timer)
{
rt=pt[i]-timer;
strcpy(p[n],p[i]);
pt[n]=rt;
et[i]=timer;
n++;
}
else
{
et[i]=pt[i];
}
i++;
wt[i]=wt[i-1]+et[i-1];
}while(i<n);
count=0;
for(i=0;i<m;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(p[i],p[j])==0)
{
count++;
found=j;
}
}
if(found!=0)
{
wt[i]=wt[found]-(count*timer);
count=0;
found=0;
}
}
for(i=0;i<m;i++)
{
totwt+=wt[i];
}
avgwt=(float)totwt/m;
for(i=0;i<m;i++)
{
printf("\n%s\t%d\t%d",p[i],pt[i],wt[i]);
}
printf("\ntotal waiting time %d\n",totwt);
printf("total avgtime %f",avgwt);
}
Output:-
enter the process name : aaa
enter the processing time : 4
enter the process name : bbb
enter the processing time : 3
enter the process name : ccc
enter the processing time : 2
enter the process name : ddd
enter the processing time : 5
enter the process name : eee
enter the processing time : 1
Practical:- 6
Que-6. Generate safe sequence to avoid deadlock
. Solution:-
#include<stdio.h>
#include<conio.h>
struct process
int all[6],max[6],need[6],finished,request[6];
}p[10];
int avail[6],sseq[10],ss=0,check1=0,check2=0,n,pid,work[6];
int nor,nori;
void main()
int safeseq(void);
int ch,i=0,j=0,k,pid,ch1;
int violationcheck=0,waitcheck=0;
do
clrscr();
printf(“\n\n\t 1. Input”);
printf(“\n\n\t 2. New Request”);
printf(“\n\n\t 3. Safe State or Not”);
printf(“\n\n\t 4. print”);
printf(“\n\n\t 5. Exit”);
printf(“\n\n\t Enter ur choice : “);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
printf(“\n\n\t Enter number of processes : “);
scanf(“%d”,&n);
printf(“\n\n\t Enter the Number of Resources : “);
scanf(“%d”,&nor);
printf(“\n\n\t Enter the Available Resouces : “);
for(j=0;j<n;j++)
for(k=0;k<nor;k++)
if(j==0)
printf(“\n\n\t For Resource type %d : “,k);
scanf(“%d”,&avail[k]);
p[j].max[k]=0;
p[j].all[k]=0;
p[j].need[k]=0;
p[j].finished=0;
p[j].request[k]=0;
}
for(i=0;i<n;i++)
printf(“\n\n\t Enter Max and Allocated resources for P%d : “,i); for(j=0;j<nor;j++)
printf(“\n\n\t Enter the Max of resource %d : “,j);
scanf(“%d”,&p[i].max[j]);
printf(“\n\n\t Allocation of resource %d : “,j);
scanf(“%d”,&p[i].all[j]);
if(p[i].all[j]>p[i].max[j])
printf(“\n\n\t Allocation should be less < or == max”);
j–;
else
p[i].need[j]=p[i].max[j]-p[i].all[j];
avail[j]=avail[j]-p[i].all[j];
break;
case 2:
violationcheck=0;
waitcheck=0;
printf(“\n\n\t Requesting process id : “);
scanf(“%d”,&pid);
for(j=0;j<nor;j++)
printf(“\n\n\t Number of Request for resource %d : “,j); scanf(“%d”,&p[pid].request[j]);
if(p[pid].request[j]>p[pid].need[j])
violationcheck=1;
if(p[pid].request[j]>avail[j])
waitcheck=1;
if (violationcheck==1)
printf(“\n\n\t The Process Exceeds it’s Max Need: Terminated”);
else if(waitcheck==1)
printf(“\n\n\t Lack of Resourcess : Process State – Wait”);
else
for(j=0;j<nor;j++)
avail[j]=avail[j]-p[pid].request[j];
p[pid].all[j]=p[pid].all[j]+p[pid].request[j];
p[pid].need[j]=p[pid].need[j]-p[pid].request[j];
ch1=safeseq();
if(ch1==0)
{
printf(“\n\n\t Granting leads to Unsafe state : “);
printf(“\n\n\t Request Denied “);
for(j=0;j<nor;j++)
avail[j]=avail[j]+p[pid].request[j];
p[pid].all[j]=p[pid].all[j]-p[pid].request[j];
p[pid].need[j]=p[pid].need[j]+p[pid].request[j];
else if(ch1==1)
printf(“\n\n\t Request Committed “);
break;
case 3:
if(safeseq()==1)
printf(“\n\n\t The System is in safe state “);
else
printf(“\n\n\t The System is Not in safe state “);
break;
case 4:
printf(“\n\n\t Number of processes : %d”,n);
printf(“\n\n\t Number of Resources : %d”,nor);
printf(“\n\n\t Pid \t Max \t Allocated \t Need “);
for(i=0;i<n;i++)
printf(“\n\n\t P%d : “,i);
for(j=0;j<nor;j++)
printf(” %d “,p[i].max[j]);
printf(“\t”);
for(j=0;j<nor;j++)
printf(” %d “,p[i].all[j]);
printf(“\t”);
for(j=0;j<nor;j++)
printf(” %d “,p[i].need[j]);
printf(“\n\n\t Available : “);
for(i=0;i<nor;i++)
printf(” %d “,avail[i]);
break;
case 5:
break;
getch();
}while(ch!=5);
}
int safeseq()
int i,j,k;
ss=0;
for(j=0;j<nor;j++)
work[j]=avail[j];
for(j=0;j<n;j++)
p[j].finished=0;
for(int tk=0;tk<nor;tk++)
for(j=0;j<n;j++)
if(p[j].finished==0)
check1=0;
for(k=0;k<nor;k++)
if(p[j].need[k]<=work[k])
check1++;
if(check1==nor)
for(k=0;k<nor;k++)
work[k]=work[k]+p[j].all[k];
p[j].finished=1;
sseq[ss]=j;
ss++;
check2=0;
for(i=0;i<n;i++)
if(p[i].finished==1)
check2++;
printf(“\n\n\t”);
if(check2>=n)
printf(“\n\n\t The system is in safe state”);
for(int tj=0;tj<n;tj++)
printf(“P%d, “,sseq[tj]);
return 1;
else
printf(“\n\n\t The system is Not in safe state”);
return 0;
}
Output:-
Safe state generated – deadlock does not occurred
Practical:- 7
Que-7.To know how process works in operating system to get resources. Study of Process
Life Cycle
Solution:-
A process is a program in execution
A process is not the same as “program”
A program is a passive text of executable codes resides in disk.
A process is an active entity ripe for execution (must have aprogram counter, stack and data
section).
State of process:
New
Running
Ready
Waiting
Terminated
Practical:- 8
Que-8.To know how deadlock occurred into the system and to know how to generate safe
state
Solution:-
A deadlock is a situation where in two or more competing actions are each waiting for the other
to finish, and thus neither ever does.
In an operating system, a deadlock is a situation which occurs when a process enters a waiting
state because a resource requested by it is being held by another waiting process, which in turn is
waiting for another resource. If a process is unable to change its state indefinitely because the
resources requested by it are being used by other waiting process, then the system is said to be in
a deadlock
Necessary Conditions
A deadlock situation can arise only if all of the following conditions hold simultaneously in a
system
1.Mutual Exclusion: At least one resource must be non-shareable. Only one process can use the
resource at any given instant of time.
2.Hold and Wait: A process is currently holding at least one resource and requesting additional
resources which are being held by other processes.
3.No Preemption: The operating system must not de-allocate resources once they have been
allocated; they must be released by the holding process voluntarily.
4.Circular Wait: A process must be waiting for a resource which is being held by another
process, which in turn is waiting for the first process to release the resource. In general, there is a
set of waiting processes, P = {P1, P2, ..., PN}, such that P1 is waiting for a resource held by P2,
P2 is waiting for a resource held by P3 and so on till PN is waiting for a resource held by P1
Practical:- 9
Que-9 How remote procedure works.
Solution:-
In computer science, a remote procedure call (RPC) is an inter-process communication that
allows a computer program to cause a subroutine or procedure to execute in another address space
(commonly on another computer on a shared network) without the programmer explicitly coding
the details for this remote interaction. That is, the programmer writes essentially the same code
whether the subroutine is local to the executing program, or remote. When the software in
question uses object-oriented principles, RPC is called remote invocation or remote method
invocation.
Sequence of events during a RPC
1. The client calls the client stub. The call is a local procedure call, with parameters pushed
on to the stack in the normal way.
2. The client stub packs the parameters into a message and makes a system call to send the
message. Packing the parameters is called marshalling.
3. The kernel sends the message from the client machine to the server machine.
4. The kernel on the server machine passes the incoming packets to the server stub.
5. Finally, the server stub calls the server procedure. The reply traces the same steps in the
reverse direction.
Practical:- 10
Que-10 Study of Computer Viruses.
Solution:-
A computer virus is a computer program that can replicate itself and spread from one computer to
another. The term "virus" is also commonly, but erroneously used, to refer to other types of
malware, including but not limited to adware and spyware programs that do not have a
reproductive ability.
Viruses can increase their chances of spreading to other computers by infecting files on a network
file system or a file system that is accessed by other computers
As stated above, the term "computer virus" is sometimes used as a catch-all phrase to include all
types of malware, even those that do not have the ability to replicate themselves. Malware
includes computer viruses, computer worms, Trojan horses, most root kits, spyware, dishonest
adware and other malicious or unwanted software, including true viruses. Viruses are sometimes
confused with worms and Trojan horses, which are technically different. A worm can exploit
security vulnerabilities to spread itself automatically to other computers through networks, while
a Trojan horse is a program that appears harmless but hides malicious functions. Worms and
Trojan horses, like viruses, may harm a computer system's data or performance. Some viruses and
other malware have symptoms noticeable to the computer user, but many are surreptitious or
simply do nothing to call attention to themselves. Some viruses do nothing beyond reproducing
themselves.