For FCFS scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times. The scheduling is performed on the basis of arrival time of the processes irrespective of their other parameters. Each process will be executed according to its arrival time. Calculate the waiting time and turnaround time of each of the processes accordingly.
#include
int main( )
{
char p[10][10];
int bt[10],wt[10],tat[10],i,n;
float avgwt,avgtat;
printf("Enter no of processes: ");
scanf("%d",&n);
for(i=0;i
$ gcc fcfs_cpu.c
$ ./a.out
Enter no of processes: 3
Enter process 1 name: P1
Enter burst time : 3
Enter process 2 name: P2
Enter burst time : 2
Enter process 3 name: P3
Enter burst time : 5
P_name B_time W_time TAT
P1 3 0 3
P2 2 3 5
P3 5 5 10
Avg Waiting Time=2.666667
Avg TAT time=6.000000
For SJF(Shortest Job First) scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times. Arrange all the jobs in order with respect to their burst times. There may be two jobs in queue with the same execution time, and then FCFS approach is to be performed. Each process will be executed acco ding to the length of its burst time. Then calculate the waiting time and turnaround time of each of the processes accordingly.
#include
int main()
{
int i,j,k,n,temp;
int p[10],bt[10],wt[10],tat[10];
float avgtat,avgwt;
printf("Enter no of processes: \t");
scanf("%d",&n);
for(i=0;i
$ gcc sjf_cpu.c
$ ./a.out
Enter no of processes: 3
Enter process number : 1
Enter burst time 4
Enter process number : 2
Enter burst time 2
Enter process number : 3
Enter burst time 6
P_No B_time W_time TAT
2 2 0 2
1 4 2 6
3 6 6 12
Avg waiting time=2.666667
Avg TAT =6.666667
For round robin scheduling algorithm, read the number of processes/ jobs in the system, their CPU burst times, and the size of the time slice. Time slices are assigned to each process in equal portions and in circular order, handling all processes execution. This allows every process to get an equal chance.
#include
#include
int main()
{
int p[10],st[10],bt[10],wt[10],tat[10],n,tq;
int i,count=0,temp,sq=0;
float avgwt=0.0,avgtat=0.0;
printf("Enter number of processes: ");
scanf("%d",&n);
for(i=0;itq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i
$ gcc rr_cpu.c
$ ./a.out
Enter number of processes: 3
Enter process number: 1
Enter burst time: 10
Enter process number: 2
Enter burst time: 3
Enter process number: 3
Enter burst time: 4
Enter time quantum:2
P_NO B_Time W_Time TAT
1 10 7 17
2 3 6 9
3 4 7 11
Avg waiting time is 6.666667
Avg TAT is 12.333333
For priority scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times, and the priorities. Arrange all the jobs in order with respect to their priorities. There may be two jobs in queue with the same priority, and then FCFS approach is to be performed. Each process will be executed according to its priority. Calculate the waiting time and turnaround time of each of the processes accordingly.
#include
#include
int main()
{
int i,j,n,temp;
int p[10],pr[10],bt[10],wt[10],tat[10];
float avgtat,avgwt;
printf("Enter no of processes:\t");
scanf("%d",&n);
for(i=0;i
$ gcc priority_cpu.c
$ ./a.out
Enter no of processes: 3
Enter process number: 1
Enter burst time: 3
Enter priority: 2
Enter process number: 2
Enter burst time: 4
Enter priority: 1
Enter process number: 3
Enter burst time: 6
Enter priority: 3
P_No B_time W_time TAT
3 6 0 6
1 3 6 9
2 4 9 13
Avg waiting time=5.000000
Avg TAT time=9.333333
1. Write C programs to simulate the following CPU Scheduling algorithms
a) FCFS
b) SJF
c) RoundRobin
d) priority View Solution
2. Write programs using the I/O system calls of UNIX/LINUX operating system (open, read, write, close,fcntl, seek, stat, opendir, readdir) View Solution
3. Write a C program to simulate Bankers Algorithm for Deadlock Avoidance and Prevention. View Solution
4. Write a C program to implement the Producer – Consumer problem using semaphores using UNIX/LINUX system calls. View Solution
5. Write C programs to illustrate the following IPC mechanisms
a) Pipes
b) FIFOs
c) Message Queues
d) Shared Memory. View Solution
6. Write C programs to simulate the following memory management techniques
a) Paging
b) Segmentation View Solution
7. Write C programs to simulate Page replacement policies
a) FCFS
b) LRU
c) Optimal View Solution