11-23-2012, 07:20 PM
. Write a C program in Linux operating system to calculate the average waiting time for the given number of process with their CPU burst times.
You have to calculate average waiting time using Shortest Job First Scheduling.
For calculating avg. waiting time using SJF, you should create a child process using fork system call.
The parent process will contain an array of integers containing CPU burst times required by each process. There will be a variable int numberOfProcesses that indicates that how many elements are there in the array. Then a child process will be created which will calculate avg. waiting time using SJF and display the waiting time of each process followed by avg. waiting time.
You would need to sort the array in order to get the shortest job first in the array.
For example, using the following data in the array where the first element contain the CPU burst of Process 1 and second element corresponds to CPU burst of Process P2 and so on...:
{5 ,15,12,25,5} >> {P1, P2, P3, P4, P5}
We will sort the array in CHILD process like (processes order changed):
{5, 5, 12, 15, 25} >> {P1, P5, P3, P2, P4}
The output from the child process will be as (we will assume that all processes arrive at time zero):
Running Child for SJF................
Waiting time of process P1: 0
Waiting time of process P2: 22
Waiting time of process P3: 10
Waiting time of process P4: 37
Waiting time of process P5: 5
Avg. waiting time using SJF is: 14.8
The parent process should wait for the child process until it generates it output as given above. Once the child process terminates, the parent process resume execution and display the following line on the shell:
Well done KID!
The above line should not be displayed if fork system call fails!!!!! If fork system call fails, following line should be displayed by the parent process:
Fork failed!
kindly mujy is assinment ka solution day den jaldi...
You have to calculate average waiting time using Shortest Job First Scheduling.
For calculating avg. waiting time using SJF, you should create a child process using fork system call.
The parent process will contain an array of integers containing CPU burst times required by each process. There will be a variable int numberOfProcesses that indicates that how many elements are there in the array. Then a child process will be created which will calculate avg. waiting time using SJF and display the waiting time of each process followed by avg. waiting time.
You would need to sort the array in order to get the shortest job first in the array.
For example, using the following data in the array where the first element contain the CPU burst of Process 1 and second element corresponds to CPU burst of Process P2 and so on...:
{5 ,15,12,25,5} >> {P1, P2, P3, P4, P5}
We will sort the array in CHILD process like (processes order changed):
{5, 5, 12, 15, 25} >> {P1, P5, P3, P2, P4}
The output from the child process will be as (we will assume that all processes arrive at time zero):
Running Child for SJF................
Waiting time of process P1: 0
Waiting time of process P2: 22
Waiting time of process P3: 10
Waiting time of process P4: 37
Waiting time of process P5: 5
Avg. waiting time using SJF is: 14.8
The parent process should wait for the child process until it generates it output as given above. Once the child process terminates, the parent process resume execution and display the following line on the shell:
Well done KID!
The above line should not be displayed if fork system call fails!!!!! If fork system call fails, following line should be displayed by the parent process:
Fork failed!
kindly mujy is assinment ka solution day den jaldi...
