BCS - 303 - Lab Programs
BCS - 303 - Lab Programs
Develop a c program to implement the Process system calls (fork (), exec(), wait(), create process,
terminate process)
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("I am: %d\n", (int) getpid());
a) FCFS
// scheduling
#include<stdio.h>
// processes
wt[0] = 0;
void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[])
// bt[i] + wt[i]
// around time
printf(" %d ",(i+1));
printf(" %d",wt[i] );
printf(" %d\n",tat[i] );
printf("\n");
// Driver code
int main()
//process id's
findavgTime(processes, n, burst_time);
return 0;
}
b) SJF
#include <stdio.h>
int main()
int A[100][4];
scanf("%d", &n);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
index = i;
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
A[0][2] = 0;
A[i][2] = 0;
A[i][2] += A[j][1];
total += A[i][2];
avg_wt = (float)total / n;
total = 0;
printf("P BT WT TAT\n");
// data.
total += A[i][3];
avg_tat = (float)total / n;
}
c) Round Robin
#include<stdio.h>
int main()
int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
scanf("%d",&time_quantum);
for(time=0,count=0;remain!=0;)
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
rt[count]-=time_quantum;
time+=time_quantum;
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
return 0;
}
d) Priority.
#include<stdio.h>
struct priority_scheduling {
char process_name;
int burst_time;
int waiting_time;
int turn_around_time;
int priority;
};
int main() {
int number_of_process;
int total = 0;
// temporary structure for swapping
// swapping position
int position;
float average_waiting_time;
float average_turnaround_time;
ASCII_number++;
position = i;
position = j;
temp_process = process[i];
process[i] = process[position];
process[position] = temp_process;
// First process will not have to wait and hence has a waiting time of 0
process[0].waiting_time = 0;
process[i].waiting_time += process[j].burst_time;
total += process[i].waiting_time;
total = 0;
printf("------------------------------------------------------------\n");
total += process[i].turn_around_time;
printf("\n-----------------------------------------------------------\n");
}
return 0;