Posts

Physical machine Extended machine Processor(s) Threads Memory Processes

Operating Systems Peter Druschel and Rodrigo Rodrigues MPI-SWS and Saarland University 1 Introduction Required readings: Silberschatz/Galvin: Chapters 1-3 What is an operating system? Layer of software between the hardware and application programs. Two main functions: • Resource manager • Extended (abstract) machine OS as resource manager • mediator/coordinator: resolve conflicting resource demands • protect users from each others (and from themselves) • mechanisms and policies for control of resources, flow of information OS as extended machine • provides stable, portable, reliable, safe, well-behaved environment (ideally) • Magician: makes computer appear to be more than it really is • Single processor appears like many separate processors • Single memory made to look like many separate memories, each potentially larger than the real memory 1 Operating Systems 2 Physical machine Extended machine Processor(s) Threads Memory Processes Disks Files Network adaptors Operating Comm. channe

Lab. No. 14 Page Replacement Direction:Paging ReplacementAlgorithm in C++.

Lab. No. 14 Page Replacement Direction:Paging ReplacementAlgorithm in C++. #include using namespace std; #include int main() { intnop,nof,page[20],i,count=0; cout<<"\n\tEnter the No. of Pages:"; cin>>nop; cout<<"\n\t Enter the Reference String:"; for(i=0;i >page[i];} cout<<"\n\t Enter the No of frames:-"; cin>>nof; int frame[nof],fcount[nof]; for(i=0;i "; if(flag==0) { if(i>=nof) { int max=0,k=0; while(k<nof) { intdist=0,j1=i+1; while(j1<nop) { if(frame[k]!=page[j1]) dist++; else{ break; } j1++; } fcount[k]=dist; k++; } k=0; while(k<nof-1) { if(fcount[max]<fcount[k+1]) max=k+1; k++; } frame[max]=page[i]; } else { frame[i%nof]=page[i]; } count++; while(j<nof) { cout<<"\t|"<<frame[j]<<"|"; j++; } } i++; } cout<<"\n\t**************************************\n"; cout<<"\n\tPage Fault is:"<<count; getch(); return

Lab. No 13 Highest Response Ratio Direction:Paging Algorithm in C.

Lab. No 13 Highest Response Ratio Direction:Paging Algorithm in C. #include int main() { inti,j,n,a[50],frame[10],no,k,avail,count=0; printf("\n ENTER THE NUMBER OF PAGES:\n"); scanf("%d",&n); printf("\n ENTER THE PAGE NUMBER :\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); printf("\n ENTER THE NUMBER OF FRAMES :"); scanf("%d",&no); for(i=0;i<no;i++) frame[i]= -1; j=0; printf("\tref string\t page frames\n"); for(i=1;i<=n;i++) { printf("%d\t\t",a[i]); avail=0; for(k=0;k<no;k++) if(frame[k]==a[i]) avail=1; if (avail==0) { frame[j]=a[i]; j=(j+1)%no; count++; for(k=0;k<no;k++) printf("%d\t",frame[k]); } printf("\n"); } printf("Page Fault Is %d",count); return 0; } Output: Comments: ___________________________. Date: ______________________. Signature of Lab Instructor: _____________________.

Lab. No 12 Feed Back Scheme Direction: Feedback scheme.

Lab. No 12 Feed Back Scheme Direction: Feedback scheme. #include #include usingnamespace std; structprocess { int pid; int atime; int btime; int rtime; int priority; int stime; int etime; }; structmycomp { booloperator()(constprocess& lhs, constprocess& rhs) const { return lhs.priority > rhs.priority; } }; void printproc(process arr[],int n) { printf("\nPROCESS TABLE"); for(int i=0;i , mycomp> q1; queue q2; int time=0,turn; turn = 0; int quanta=4,rquanta=4; int flag1=0; while((!q1.empty())||(!q2.empty())||(flag1==0)||(turn 0) q2.push(q1.top()); q1.pop(); quanta=4; } } elseif(!q2.empty()) { q2.front().rtime = q2.front().rtime-1; printf("\nIn RR rtime for %d is : %d",q2.front().pid,q2.front().rtime); chart[time]=q2.front().pid; rquanta--; if(q2.front().rtime==0) { q2.pop(); rquanta=4; } elseif(rquanta==0) { printf("\trquanta is zero, removing and adding at end %d",q2.front().pid); q2.push(q2.front()); q2.pop(); rquanta=4; } } printf("

Lab. No 11 Pure Priority Scheme OS

Lab. No 11 Pure Priority Scheme Direction: 2nd Chance Page Replacement. #include #define SIZE 3 int full=0;//To check whether all frames are filled int a[21];//To take the input intref[SIZE];//This is for reference bits for each frame int frame[SIZE]; int repptr=0;//Initialised to first frame int count=0; int display() { int i; printf("\nThe elements in the frame are\n"); for(i=0;i<full;i++) printf("%d\n",frame[i]); } int Pagerep(int ele) { int temp; /*Whenever a page needs to be replaced the repptr moves from page to page checking whether it's reference bit is 0 or not, if it is 0 itcoomes out of the while loop and if it is one, it gives a second chance setting the reference bit to 0*/ while(ref[repptr]!=0) { ref[repptr++]=0; if(repptr==SIZE) repptr=0; } temp=frame[repptr]; frame[repptr]=ele; ref[repptr]=1;//The latest page reference, hence it is set to 1 return temp; } int Pagefault(int ele) { if(full!=SIZE) { ref[full]=1;//All t

Lab 10 Memory Management in Paging Scheme On OS

Lab 10 Memory Management in Paging Scheme In computer operating systems, paging is a memory management scheme by which a computer stores and retrieves data from secondary storage[a] for use in main memory. In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. Paging is an important part of virtual memory implementations in modern operating systems, using secondary storage to let programs exceed the size of available physical memory. For simplicity, main memory is called "RAM" (abbreviated from "random-access memory") and secondary storage is called "disk" (a shorthand for "hard disk drive"), but the concepts do not depend on whether these terms apply literally to a specific computer system. Direction: Memory Management in Paging Scheme in C. #include #include int main() { int st[10], bt[10], wt[10], tat[10], n, tq; int i, count=0, swt=0, stat=0, temp, sq=0; float awt=0.0, atat=0.0; printf

Lab. No 9 Virtual Round Robin Best Operating System

Lab. No 9 Virtual Round Robin Virtual- Time Round-Robin (VTRR), a proportional share scheduler that can provide good proportional sharing accuracy with O(1) scheduling overhead. VTRR achieves this by combining the benefits of fair queuing algorithms with a round-robin scheduling mechanism. Unlike many other schedulers, VTRR is simple to implement. VTRR provides accurate proportional share allocation with constant, sub-microsecond scheduling overhead. The scheduling overhead using VTRR is two orders of magnitude less than the standard Linux scheduler for large numbers of clients. Direction: Virtual Round Robinin C++. #include int main() { intcount,j,n,time,remain,flag=0,time_quantum; intwait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; printf("Enter Total Process:\t "); scanf("%d",&n); remain=n; for(count=0;count 0) { time+=rt[count]; rt[count]=0; flag=1; } else if(rt[count]>0) { rt[count]-=time_quantum; time+=time_quantum; } if(rt[coun