FIRST COME FIRST SERVE
-
Upload
kaviarasud -
Category
Documents
-
view
629 -
download
0
Transcript of FIRST COME FIRST SERVE
![Page 1: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/1.jpg)
FIRST COME FIRST SERVE
Aim:
To write a c program to perform First come First serve CPU scheduling operation.
ALGORITHM
Step 1: Start
Step 2: Read the number of process.
Step 3: Read each process and its burst time.
Step 4: Print the Gantt chart
Step 5: Initialize i-0.
Step 6: Repeat step 7-8 until i >=n is false.
Step 7: Print the process.
Step 8: Compute t=t + bt[i];
Step 9: Initialize I =1.
Step 10: Print the process and waiting time.
Step 11: Compute awt= awt and wt =wt + bt[i].
Step 12: Increment i value.
Step 13: Print the total waiting time and average time.
Step 14: Print Turn Around time.
Step 15: Stop.
PRIORITY SCHEDULING
Aim:
To write a c program to perform Priority CPU scheduling operation.
ALGORITHM
1. Start
2. Read the number of process and its burst time.
3. Read the Priority for each process.
4. Repeat step 7-12 until i<=n is false.
5. Initialize j =i+1.
6. Repeat step 9-10 until j<=n is false.
7. Check whether pri[i]>pri[j] is true or not whether pri[i]>pri[j] is true, if so then assign the
following.
8. Temp=bt[i],strcpy(temp1,p[i]),bt[j] = bt[j],strcpy(temp1,p[j]),tot[j] = temp,
strcpy(p[j],temp1),temp = pri[i],pri[i]= pri[j],pri[j]=temp.
9. Increment j value.
![Page 2: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/2.jpg)
10. Increment i value.
11. Increment both i and j.
12. Print each process one by one using loop.
13. Initialize i=1.
14. Repeat step 15 -17 until i<=n+1 is false.
15. Print the t value.
16. Compute t= t+bt[i];
17. Increment i value.
18. Initialize i=1.
19. Repeat step 20-22 until i<=n is false
20. Print the waiting time
21. Increment i value
22. Int i=0 repeat step 24-26 until i<=n-1 is false
23. Compute tt= tt + bt[i+1],att = att +tt and print the tt.
24. Increment i value.
25. Print Total Turn around Time and Average Turn Around time.
26. Stop
SHORTEST JOB FIRST
Aim:
To write a c program to perform Shortest Job First CPU scheduling operation.
ALGORITHM
1. Start
2. Read the process to be allocated
3. Read the number of process and its burst time.
4. Initialize i=1.
5. Repeat step 6-11 until i<=n is false.
6. Initialize j =i+1.
7. Repeat step 8-10 until i<=n is false.
8. Check whether bt[i]>bt[j] is true or not. if so, then temp=bt[i].strcpy(temp p[i]).
9. Assign bt[i]=bt[j],strcpy(p[i],p[j]),temp and strcpy(p[j],temp).
10. Increment both j and i.
11. Increment i=1, Repeat step 14 -16 until i<=n+1 is false.
12. Print the t value.
13. Compute t =t + bt[i].
14. Increment i value.
15. Increment i=1,
![Page 3: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/3.jpg)
16. Repeat step 17 -18 until i<=n is false.
17. Print the Waiting time p[i],wt.
18. Print the Total waiting time and Average waiting time.
19. Int i=0, repeat step 21-22 i\until i<=n-1 is false.
20. Compute tt= tt + bt[i+1] and print the values.
21. Compute att = att +tt.
22. Increment i value.
23. Print Total Turn around Time and Average Turn Around time.
24. Stop
ROUND ROBIN SCHEDULING
Aim:
To write a c program to perform Round Robin CPU scheduling operation.
ALGORITHM
1. Start
2. Read the number of process and its burst time.
3. Read the appropriate time slice.
4. Check whether n! = 0 is true or not. If so then initialize i=1.
5. Repeat step 6-7 until i<=n is false.
6. Check whether b1 [i]>ts is true or not. If so then m = m+ ts, t1 [2] =m, b1 [i] =b1 [i]-ts.
7. Increment i value
8. Print the program p[i] and increment temp of i by one and z=z + 1.
9. Check else whether b[i]! = o is true or not.
10. Assign w[i]= m-temp[i] *ts.
11. Print the process p[i].
12. Calculate awt = w[i],mt=b1[i],t1[2]=m.
13. Assign z1=z and initialize 1=0.
14. Repeat step 14-15 until i<=2 is false.
15. Print the t1 [i] value.
16. Increment i value, initialize i=1.
17. Repeat step 19-20 until i<n is false.
18. Print the following waiting time for each process.
19. Increment the i value.
20. Compute aw=aw/n.
21. Print the average waiting time.
22. Initialize i=1 repeat step 23-24 until i<=n is false.
23. Print the Turn around time of each process.
![Page 4: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/4.jpg)
24. Increment i value.
25. Compute at = at/n and print Average.
26. Stop.
PRODUCER CONSUMER PROBLEM
Aim:
To write a c program to perform the Producer Consumer Problem.
ALGORITHM
Step 1: Start
Step 2: Read the status of the buffer.
Step 3: Check whether n=0 is true or not. If so then call the procedure function.
Step 4: If n=1 then call the consumer function.
Step 5: When producer function is called then calculate n = n+1 and f = f+1.
Step 6: Print the producer value.
Step 7: When consumer function is called then update n= n-1.
Step 8: Print the consumer value.
Step 9: Stop.
READER_WRITER PROBLEM
Aim:
To write a c program to perform the Reader Writer Problem.
ALGORITHM
Step 1: Start
Step 2: Read the total number of process.
Step 3: Read the status of the process whether it is writing or reading.
Step 4: If the status is writing then read for other waiting process into memory.
Step 5: Repeat step 4 until the process status is checked.
Step 6: Print all the reading and writing process separately.
Step 7: Stop.
DINING PHILOSOPHER PROBLEM
Aim:
![Page 5: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/5.jpg)
To write a c program to perform the Dining Philosopher Problem
ALGORITHM
Step 1: Start
Step 2: Initialize i=1 and n=5.
Step 3: Repeat step 4-5 until i<=n is false.
Step 4: Read the status of Philosopher.
Step 5: Increment i value.
Step 6: If the status =1, then it is called ‘Hungry’.
Step 7: If the status =2, then it is called ‘Eating’.
Step 8: If the status =3, then it is called ‘Thinking’.
Step 9: Only two Philosophers can be able to eat at a time and they must set alternatively.
Step 10: Stop.
SAFETY ALGORITHM
Aim:
To write a c program to perform Banker’s Safety Algorithm.
ALGORITHM
1. Start
2. Read the number of process and resources.
3. Read the allocation for each process.
4. Let work and finish be vector of length m and h respectively.
5. Initialize work= available and finish [i] = false.
6. Find an i such that both finish [i] = false and need i<=work. if no such i exist goto step 8.
7. Assign work=work + allocation and finish[i] =true goto step 6.
8. If finish [i] = true for all i then system is in safe state.
9. Stop.
RESOURCE REQUEST ALGORITHM
Aim:
To write a c program to perform Banker’s Resource Request Algorithm.
ALGORITHM
![Page 6: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/6.jpg)
1. Start
2. Read the number of process and resources.
3. Read the allocation list, maximum and its request.
4. Assign work finish. If request i<=available goto step 6, otherwise raise an error
condition.
5. If request i<=available goto step 7, otherwise pi must wait.
6. Modify the state as, available= available – request 1 and need i= need i-request.
7. The resulting would be in safe state and print the order of execution.
8. Stop.
FIFO
Aim:
To write a c program to perform Page replacement algorithm using FIFO(First In First
Out) operation.
ALGORITHM
Step 1: Start
Step 2: Read the number of Frames and Reference.
Step 3: Read the Frame list.
Step 4: Copy the reference list into stack.
Step 5: Insert the frame number into the frame by FIFO.
Step 6: Display the frame stack.
Step 7: Stop.
OPTIMAL PAGE REPLCAEMNET
Aim:
To write a c program to perform Page replacement algorithm using Optimal operation.
ALGORITHM
Step 1: Start
Step 2: Read the number of Frame, Reference and Reference list.
Step 3: Replace the page fault that will not be used for longer period of time.
Step 4: Count and print the number of page fault occurs.
Step 5: Display the Reference list stack.
Step 6: Stop.
![Page 7: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/7.jpg)
LRU PAGE REPLCAEMNET
Aim:
To write a c program to perform Page replacement algorithm using LRU operation.
ALGORITHM
1. Start
2. Read the number of Frames, Reference and Reference list values.
3. Insert the element into the frame by replacing the last recently used.
4. While inserting an element 1,the frame contents also having the same element i occur
then print No page faults.
5. Otherwise, print page fault occurs.
6. Stop.
LINUX
ARITHMETIC OPERATION
Aim:
To write a Linux program for the Arithmetic Operation
ALGORITHM
Step 1: Start
Step 2: Read a and b.
Step 3: Check the condition using while loop is executed until ch is yes.
Step 4: Read the values of choice.
Step 5: Case
1. c=’expr $a + $b’
2. c=’expr $a - $b’
3. c=’expr $a\* $b’
4. c=’expr $a / $b’
Step 6: Print the result is c.
Step 7: Check the condition using if statement if option is equal to n then continue else exit.
Step 8: Stop.
SUM OF DIGITS
Aim:
![Page 8: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/8.jpg)
To write a Linux program to display Sum of Digits.
ALGORITHM
Step 1: Start
Step 2: Read the value of n.
Step 3: Check if n less than or equal to 9 then print the value n.
Step 4: Calculate C=9%9.
Step 5: Check if C is equal to 0 then print 9.
Step 6: Else print the value of C.
Step 7: Stop.
FACTORIAL USING RECURSION
Aim:
To write a Linux program for the Factorial for given number.
ALGORITHM
Step 1: Start
Step 2: Read the value of n.
Step 3: Initialize i=1 and f=1.
Step 4: Call the function fact.
Step 5: Print the value of fact.
Step 6: Stop.
fact():
Step 1: Start
Step 2: Check the condition is less than or equal to n by using the if condition.
Step 3: f=’expr $f \* $i’
i=’expr $i+1’
Step 4: Else return the value.
BINOMIAL COEFFICEINT OF NCR
Aim:
To write a Linux program to find the number of combination of n things taken.
ALGORITHM
![Page 9: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/9.jpg)
Step 1: Start
Step 2: Read n and r
Step 3: Assign z= n, k= n, and i=1
Step 4: By using the while loop satisfy the condition is less then r do
Step 5: k=’expr $k-1’
n=’expr $n\* $k’
i=’expr $i+1’
Step 6: Assign b=1 and c=1
Step 7: If c has less than r then do
Step 8: b=’expr $b \* $c’
c=’expr $c+1’
Step 9: Assign r=1 and y=1
Step 10:By using while loop check the condition y less than m then do
Step 11:x=’expr $x\* $y’
y=’expr $y + 1’
Step 12:Print the value of n – is x
Step 13:Result =’expr $n / $res’
Step 14:Print the result
Step 15:Stop.
PRIME NUMBER CHECKING
AIM:
To write a Linux program to check the given number is Prime number or Not.
ALGORITHM:
Step 1: Start
Step 2: Get the value n
![Page 10: FIRST COME FIRST SERVE](https://reader035.fdocuments.net/reader035/viewer/2022081807/549e3526b3795996618b4658/html5/thumbnails/10.jpg)
Step 3: By using if statements check the condition ($n-le 1) then assign f=0
Step 4: Initialize i=2 and j=1
Step 5: By using the while loop check the condition ($i-lt $n) then do
Step 6: m=’expr $n % $q’
Step 7: By using if condition m is equal to zero
Step 8: Print n is not a prime number
Step 9: Else print n is a prime number
Step 10: Stop
PRIME NUMBER GENERATION
AIM:
To write a Linux program for the generation of Prime number series.
ALGORITHM:
Step 1: Start
Step 2: Read sr,fr
Step 3: If sr less than 2 is true then assign sr=2
Step 4: Assign k=sr, p=1 and i=2
Step 5: By using while loop check the condition i less than k do
Step 6: M=’expr $k % $i’
Step 7: If the condition m is equal to zero than p=0 and i= i+1
Step 8: If the value of p is equal to 1 then k=k+1
Step 9: Print the series
Step 10: Stop