Skip to content
Snippets Groups Projects
Commit 014e1c06 authored by antux18's avatar antux18
Browse files

t5 + t6.

parent d48a27fc
Branches
No related merge requests found
......@@ -14,20 +14,45 @@ void init_processes(struct process *);
void display(struct process *);
void display_average_waiting_time(struct process *);
void schedule_FCFS(struct process *);
void schedule_SJF(struct process * arr);
void schedule_LJF(struct process * arr);
int main()
{
struct process processes[SIZE];
struct process processes[SIZE];
// FCFS:
init_processes(processes);
printf("Orignial input (processes)\n");
display(processes);
schedule_FCFS(processes);
printf("Execution according to FCFS policy\n");
display(processes);
display_average_waiting_time(processes);
display_average_waiting_time(processes);
// SJF:
init_processes(processes);
printf("Orignial input (processes)\n");
display(processes);
schedule_SJF(processes);
printf("Execution according to SJF policy\n");
display(processes);
display_average_waiting_time(processes);
// LJF:
init_processes(processes);
printf("Orignial input (processes)\n");
display(processes);
schedule_LJF(processes);
printf("Execution according to LJF policy\n");
display(processes);
display_average_waiting_time(processes);
}
void init_processes(struct process * input)
{
......@@ -37,36 +62,76 @@ void init_processes(struct process * input)
input[i].arrival_time = rand()%10;
input[i].execution_time = rand()%10;
input[i].process_id= i;
input[i].start_time=-1;
}
input[i].start_time=-1;
}
}
void display(struct process * input){
printf("process<id, arr, exe, start>:");
for(int i=0;i<SIZE;i++)
{
printf("<%d,%d,%d,%d> ", input[i].process_id,
input[i].arrival_time, input[i].execution_time, input[i].start_time);
input[i].arrival_time, input[i].execution_time, input[i].start_time);
}
printf("\n");
}
void schedule_FCFS(struct process * arr)
{
//TODO
printf("Not implemented Yet!\n");
int min_index, min_value;
int start_time = 0;
for (int i = 0 ; i < SIZE ; i++) {
min_index = 0;
min_value = 11;
for (int j = 0 ; j < SIZE ; j++) {
if (arr[j].start_time == -1 && arr[j].arrival_time <= min_value) {
min_index = j;
min_value = arr[j].arrival_time;
}
}
arr[min_index].start_time = start_time;
start_time += arr[min_index].execution_time;
}
}
void schedule_SJF(struct process * arr)
{
//TODO
printf("Not implemented Yet!\n");
int min_index, min_value;
int start_time = 0;
for (int i = 0 ; i < SIZE ; i++) {
min_index = 0;
min_value = 11;
for (int j = 0 ; j < SIZE ; j++) {
if (arr[j].start_time == -1 && arr[j].execution_time <= min_value) {
min_index = j;
min_value = arr[j].execution_time;
}
}
arr[min_index].start_time = start_time;
start_time += arr[min_index].execution_time;
}
}
void schedule_LJF(struct process * arr)
{
//TODO
printf("Not implemented Yet!\n");
int max_index, max_value;
int start_time = 0;
for (int i = 0 ; i < SIZE ; i++) {
max_index = 0;
max_value = 0;
for (int j = 0 ; j < SIZE ; j++) {
if (arr[j].start_time == -1 && arr[j].execution_time >= max_value) {
max_index = j;
max_value = arr[j].execution_time;
}
}
arr[max_index].start_time = start_time;
start_time += arr[max_index].execution_time;
}
}
void display_average_waiting_time(struct process * arr)
{
//TODO
printf("Not implemented Yet!\n");
int sum = 0;
for (int i = 0 ; i < SIZE ; i++) {
sum += arr[i].start_time;
}
printf("Average waiting time: %d\n", sum/SIZE);
}
# Explain the difference between parallelism and concurrency for this exercise
Concurrency is a degree parallelism at the software level, but doesn't demonstrate parallelism in time, rather in the accomplished tasks that will be divided amongst many threads. Those threads won't operate all at the same time, but rather at different moments. Concurrency can be operated on a single core CPU.
Parallelism, however, is true parallelism at hardware level, meaning multiple parallel tasks will be executed at the same time, thus demonstrating parallelism in time. Parallelism requires multiple CPU cores that can simultaneously handle multiple threads.
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment