operating system practical file, Slides of Operating Systems

Operating system practical file .

Typology: Slides

2020/2021

Uploaded on 12/02/2022

46-minakshi-singh
46-minakshi-singh 🇮🇳

1 document

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Operating
System
Practical file
Submitted by: Submitted to:
Minakshi Singh Dr. Vandana
(21570046) Gupta
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download operating system practical file and more Slides Operating Systems in PDF only on Docsity!

Operating

System

Practical file

Submitted by: Submitted to:

Minakshi Singh Dr. Vandana

(21570046) Gupta

Que 1 ) Write a program using fork and exec where

parent and child execute the :

a)Same code and same program

b)Same program and different program

a)

Output:

Que 2 ) Writ a program to report behaviour of Linux

kernel including kernel version. CPU type and model.

Output:

Que 3) Write a program to report behaviour of linux

kernel including information on 19 configured

memory , amount of free and used memory.(memory

information).

Que 5 ) Write a program to copy files using system

calls.

Que 6 ) Write a program to impement FCFS

scheduling algorithm.

#include #include<stdio.h> using namespace std; class fcfs { public: int burst_tm,arv_tm,wait_tm; char pid; }; int main() { int n,sum=0,carry; cout<<"Enter the no. of processes:\n"; cin>>n; fcfs temp; fcfs *f=new fcfs[n]; for( int i=0;i<n;i++) { cout<<"Enter the process id:\n"; cin>>f[i].pid; cout<<"Enter the burst timing:\n"; cin>>f[i].burst_tm; cout<<"Enter the arrival timing:\n"; cin>>f[i].arv_tm; //system("cls"); } int k=0,flag=1; while(k!=0) { if(f[k].arv_tm==0) { flag=0; break; } k++;

cout<<"average turn around time:
n"<<avg_around_tm<<endl<<"average waiting time:
n"<<avg_wait_tm<<endl; return 0; }

Que 7) Write a program to implement Round Robin

scheduling algorithm.

#include using namespace std; //ducslectures.blogspot.in class sched { public: int n,bt[10],at[10],tat[10],wt[10],rt[10],finish[10],twt,ttat,tota l; void readData(); void Init(); void dispTime(); void computeRR(); }; void sched::readData() { cout<<"Enter no. of processes\n"; cin>>n; cout<<"Enter the burst times in order :\n"; for(int i=0;i<n;i++) cin>>bt[i]; cout<<"Enter the arrival times in order:\n"; for(int i=0;i<n;i++) cin>>at[i]; } void sched::Init() {

cout<<"Gantt Chart\n "; for(time=0;time<total;) { for(i=0;i<n;i++) { if(at[i]<=time && finish[i]==0) { cout<<"("<<time<<")|==P"<<(i+1)<<"==|"; if(rt[i]<q) { dec=rt[i]; } else {dec=q;} rt[i]=rt[i]-dec; if(rt[i]==0) finish[i]=1; for(j=0;j<n;j++) if(j!=i && finish[j]==0 && at[j]<=time) wt[j]+=dec; time=time+dec; } } } //ducslectures.blogspot.in cout<<"("<<total<<")"<<endl; dispTime(); } int main() { sched s; int ch; s.computeRR();

if(f[k].arv_tm==0) { flag=0; break; } k++; } if(!flag) { cout<<"enter all values of arival time as no arrival time is 0\n"; return 1; } for(k=0;k<n;k++) { temp=f[k]; for(int i=k+1;i<n;i++) { if(temp.burst_tm>f[i].burst_tm) { temp=f[i]; f[i]=f[k]; f[k]=temp; } } } cout<<"Entered info is as follows:\n"; float avg_wait_tm=0,avg_around_tm=0; for(k=0;k<n;k++) { f[k].wait_tm=sum-f[k].arv_tm; if(f[k].wait_tm<0) f[k].wait_tm=0; if(f[k].arv_tm>(f[k-1].burst_tm+f[k-

1].arv_tm)) { carry=f[k].arv_tm-sum; sum+=(f[k].burst_tm+carry); } else sum+=f[k].burst_tm; avg_wait_tm+=f[k].wait_tm; avg_around_tm+=f[k].wait_tm+f[k].burst_tm; } avg_around_tm/=n; avg_wait_tm/=n; for(k=0;k<n;k++) { cout<<"pid: "<<f[k].pid<<endl<<"Burst time: "<<f[k].burst_tm<<endl<<"arrival time: "<<f[k].arv_tm<<endl<<"Waiting time:

sjf *f=new sjf[n]; for( int i=0;i<n;i++) { cout<<"Enter the process id:\n"; cin>>f[i].pid; cout<<"Enter the burst timing:\n"; cin>>f[i].burst_tm; cout<<"Enter the arrival timing:\n"; cin>>f[i].arv_tm; } int k1=0,flag=1; while(k1<n) { if(f[k1].arv_tm==0) { flag=0; break; } k1++; } if(flag==1) { cout<<"enter all values of arival time as no arrival time is 0\n"; return 1; } for(int k=0;k<n;k++) { temp=f[k]; for(int i=k+1;i<n;i++) { if(temp.arv_tm>f[i].arv_tm) { temp=f[i]; f[i]=f[k]; f[k]=temp; } //cout<<"f[0]: "<<f[0].pid<<endl; } }

for(int k=0;k<n;k++) { cout<<"pid: "<<f[k].pid<<endl<<"Burst time: "<<f[k].burst_tm<<endl<<"arrival time: "<<f[k].arv_tm<<endl<<"Waiting time: "<<f[k].wait_tm<<endl; } cout<<"Entered info is as follows:\n"; carry=f[0].arv_tm; int i=0; for(int k=1;k<n;k++) { if(f[k].arv_tm==carry) { if(f[i].burst_tm>f[k].burst_tm) i=k; } else { cout<<"carry break\n"; break; } } int j,tem=0,k,b; do { j=0; if((f[i].arv_tm<=sum)&&(f[i].temp!=1)) { f[i].wait_tm=sum-f[i].arv_tm; f[i].temp=1; sum+=f[i].burst_tm; } else { if(tem==0) { sum=f[i].arv_tm; tem=1;