/OS-Scheduler

📢 A CPU scheduler that determines an order for the execution of its scheduled processes. Operating System Scheduler decides which process will run according to a certain data structure that keeps track of the processes in the system and their status.

Primary LanguageCMIT LicenseMIT

Operating System Scheduler

logo


Table of Contents


Overview


  • A CPU scheduler determines an order for the execution of its scheduled processes.
  • It decides which process will run according to a certain data structure that keeps track of the processes in the system and their status.
  • A process, upon creation, has one of the three states: Running, Ready, Blocked (doing I/O, using other resources than CPU or waiting on unavailable resource).
  • A bad scheduler will make a very bad operating system, so your scheduler should be as much optimized as possible in terms of memory and time usage.
  • The Project has 2 phases.


  • Built using C language.

Get Started

  1. Clone the repository.
    git clone https://github.com/AdhamAliAbdelAal/OS-Project
    
  2. You will need to set up the platform Linux.

  3. Install a C Compiler on Linux if you haven't.
    sudo dnf install gcc
    

Path of the program

  1. Go to folder Phase 1 or Phase 2 , as you wish.
  2. Place the input in file "processes.txt" or run file "test_generator.c" and it will generate random input

    • Phase 1

    • Phase 2


  3. Open terminal
  4. Build file process_generator.c.

  5. gcc process_generator.c -o ex
    
  6. Run ex.

  7. ./ex
    

  8. Choose a scheduling algorithm.

  9. Input Algorithm
    1 Non-preemptive Highest Priority First (HPF)
    2 Shortest Remaining time Next (SRTN)
    3 Round Robin (RR)


  10. There are 2 output files "scheduler.Log" and "scheduler.perf". "memory.log" is created in phase 2.

    • Scheduler.Log


    • Scheduler.perf

    • Memory.log


Data Structures Used


  1. Queue
  2. Priority Queue
  3. Process Data
    • Arrival time
    • Priority
    • Run time
    • ID
    • Memsize
  4. Memory Node
    • Size
    • Start
    • Pointer to the next memory node
  5. PCB for each process
    • ID
    • PID
    • Arrival time
    • Burst time
    • Finish time
    • Running time
    • Stop time
    • Priority
    • Start time
    • Start Address in memory
    • Memory Size

Algorithms Explanation


  1. HPF
    • The main loop checks if the processes are all finished or not.
    • In an inner loop, we get all the processes arrived at this particular second and enqueue them in the ready queue.
    • If there is no current process and the ready queue isn’t empty, we directly pop from the ready queue as it’s already sorted with the minimum priority, then start the process, fork it, and execl Process.c.
    • Last check: If the remaining time of the running process is zero, then it is finished and the running process is set to NULL. The finished processes counter is incremented as well and the loop continues.
  2. SRTN
    • Receiving the processes from the process generator.
    • Checking if the coming process's burst time is smaller than the remaining time of the running process.
    • If it's smaller than the running process will be added to the ready queue and saved in stop resuming queue and the smaller one will be the running process.
    • Then every time we a process starts then we check if this process was stopped before “existing in stop resuming queue" or not to know if it started or resumed to resume the stopped process.
  3. RR
    • Check if there are arriving processes, receive them in ready queue.
    • Check if there is a processes finished or the time slot ended, change the state of the process from running to finished or ready respectively.
    • Check if there are processes in ready queue and no process is running so pick up one of them and run it.

Assumptions


  1. In the memory waiting queue, it is implemented as a priority queue based on the algorithm so if it’s a SRTN, the priority is the remaining time while for RR, it is based on the memory size where the smaller one gets put into the ready queue first. As for the HPF, there is no need since the running process is the only one put into the ready queue.

  2. We made an array of arrivals in the process generator as a shared memory with the scheduler in order to make sure that any process arriving at a specific time is read by the scheduler and not skipped.

  3. We synchronize between the stopped process and the arrived one if they come in the same second so that the stopped process is put into the queue before the arrived process.

File Structure



Contributors


Abdelrahman Noaman


Abdelrahman Hamdy


Adham Ali


Eslam Ashraf

🔒 License

This software is licensed under MIT License, See License for more information ©AdhamAliAbdelAal.