[Operating System] Scheduling Algorithm Implementation

hina·2023년 7월 6일
0

Operating System

목록 보기
4/9

Implementation


1. FCFS

void schedule() 
{
    Task *current;

    // print task list (sanity checker)
    traverse(head);

	current = pickNextTask();
        
    run(current, current->burst);

    delete(&head, current);
}

Task *pickNextTask()
{
    return head->task;
}

2. SJF

void schedule()
{
    Task* current;

    // print task list (sanity checker)
    traverse(head);

    current = pickNextTask();

    run(current, current->burst);

    delete(&head, current);
}

Task* pickNextTask()
{
    int min_burst = 9999;
    struct node* cur_node = head;
    struct node* min_node = head;

    while (cur_node != NULL) {
        if (cur_node->task->burst < min_burst) {
            min_burst = cur_node->task->burst;
            min_node = cur_node;
        }
        cur_node = cur_node->next;
    }

    return min_node->task;
}

3. Round Robin

void schedule()
{
    Task* current;

    // print task list (sanity checker)
    traverse(head);

    current = pickNextTask();
    if (QUANTUM <= current->remaining_burst) {
        run(current, QUANTUM);
        if (current->remaining_burst > 0) {
            insert(&head, current);
        }
    }
    else {
        run(current, current->remaining_burst);
    }
    delete(&head, current);
}

Task* pickNextTask()
{
    return head->task;
}

4. Priority

void schedule() 
{
    Task *current;
	
    // print task list (sanity checker)
    traverse(head);

    current = pickNextTask();

    run(current, current->burst);

    delete(&head, current);
}

Task *pickNextTask()
{
    int priority_min = 9999;
    struct node* cur_node = head;
    struct node* min_node = head;

    while (cur_node != NULL) {
        if (cur_node->task->priority < priority_min) {
            priority_min = cur_node->task->priority;
            min_node = cur_node;
        }
        cur_node = cur_node->next;
    }

    return min_node->task;
}

Result


각 알고리즘 별 수행 결과

Algorithmaverage waiting time
FCFS267.938
SJF160.438
RR236.000
Priority181.375
profile
🖥️

0개의 댓글