Vous êtes sur la page 1sur 5

Shekhar.moger17@gmail.

com

Context switching A process runs on the CPU until it is context switched. This happens when one of the following occurs:

The process exits. The process uses up its time slice. The process requires another resource that is not currently available or needs to wait for I/O to complete. A resource has become available for a sleeping process. If there is a higher priority process ready to run, the kernel will run this instead (the current process is preempted).

Non-Preemptive scheduling Once a process enters the running state (allowed the resources to run), it cannot be removed from the processor until it has completed its service time. Ex Ticket issue case one by one

Preemptive scheduling It driven by the notion of prioritized computation. It requires that the process with the highest priority should always be the one currently using the processor. If a process is currently using the processor and a new process with a higher priority enters the ready list, the process on the processor should be removed and returned to the ready list until it is once again the highest-priority process in the system. Ex Minister is coming

FCFS Algorithm FCFS (First-Come, First-Served) or FIFO (First-In, First-Out) is one of the simplest and easily implementable algorithm techniques. The FCFS algorithm simply puts the processes up for processing in the same order as they arrive in the ready queue. When a process comes in, it is added to the tail of ready queue. When a running process terminates, it is removed and the process at the head of ready queue is set to run. FIFO is a non-preemptive algorithm, i.e. no process can be forced to give-up its resources in case a higher-priority process arrives in the queue. Advantages of FCFS: The greatest strength of this algorithm is that it is easy to understand and equally easy to program. It is also fair in the same sense that allocating scarce sports or concert tickets to people who are willing to stand on line starting at 2 A.M. is fair.

Disadvantages of FCFS: Unfortunately, FCFS also has a huge disadvantage, and it is that it pays no attention to processing time or prioritizes the processes. If a process arrives in the ready queue with processing time of 100ms and then several other processes arrive with processing time of 1ms each, the FCFS will start the 100ms process and other, much shorter processes will have to wait for 100ms.

Formula for waiting time is Starting time arrival time of that process.

The formula for TAT is

By looking we can say 27-0 =27

Or (Finish time starting time) + waiting time. 27 - 24 +24 = 27

i get into a hotel ...... arrival time i am sitting in the seat waiter keeps the food on the table ..... i start eating my food ....... start time i start eating at 5 i finished eating in certain limit may be by one hour so that i can catch a movie by 6 pm so that one hour is my ...... burst time i finish by 6 pm ...... so that wouldbe my finish time from the time i arrived to the time i fished would be my tat

#include<stdio.h> #include<conio.h> void main() { char pn[10][10]; int arr[10],bur[10],star[10],finish[10],tat[10],wt[10],i,n; int totwt=0,tottat=0,count=0; clrscr(); printf("Enter the number of processes:"); scanf("%d",&n); for(i=0;i<n;i++) // to take in the details { printf("Enter the Process Name, Arrival Time & Burst Time:"); scanf("%s%d%d",&pn[i],&arr[i],&bur[i]); }

for(i=0;i<n;i++) // to access all the process on by one { count++; // for context switch if(i==0) // check for first process { star[i]=arr[i]; // start time equal to arrival time wt[i]=star[i]-arr[i]; // wait time finish[i]=star[i]+bur[i]; // finish time tat[i]=finish[i]-arr[i]; // tat } else /// any other process that is for p2 p3 ..pn { star[i]=finish[i-1]; wt[i]=star[i]-arr[i]; finish[i]=star[i]+bur[i]; tat[i]=finish[i]-arr[i]; } } printf("\nPName Arrtime Burtime Start TAT Finish"); for(i=0;i<n;i++) { printf("\n%s\t%6d\t\t%6d\t%6d\t%6d\t%6d",pn[i],arr[i],bur[i],star[i],tat[i],finish[i]); // for space totwt+=wt[i]; tottat+=tat[i]; } printf("\nNo of context switches=%d\n",count); printf("\nAverage Waiting time:%f",(float)totwt/n); printf("\nAverage Turn Around Time:%f",(float)tottat/n); getch(); }

OUTPUT: Input: Enter the number of processes: 3 Enter the Process Name, Arrival Time & Burst Time: 1 2 3 Enter the Process Name, Arrival Time & Burst Time: 2 5 6 Enter the Process Name, Arrival Time & Burst Time: 3 6 7 Output: PName Arr_time Burst_time Start_time TAT Finish 1 2 3 2 3 5

2 3

5 6

6 7

5 6

6 7

4 10

No of context switches 3 Average Waiting Time: 3.333 Average Turn Around Time: 7.000

Vous aimerez peut-être aussi