{"id":19446577,"url":"https://github.com/imsatyasaiteja/cpu-scheduling","last_synced_at":"2026-06-10T22:31:30.193Z","repository":{"id":177247553,"uuid":"582235798","full_name":"imsatyasaiteja/Cpu-Scheduling","owner":"imsatyasaiteja","description":"C++ program that can create an array of processes and perform CPU scheduling by implementing the First-Come-First-Serve, Round-Robin, and Completely-Fair-Scheduler algorithms.","archived":false,"fork":false,"pushed_at":"2023-02-20T11:05:33.000Z","size":53,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T08:42:11.007Z","etag":null,"topics":["completely-fair-scheduler","cpu-scheduling-algorithms","dynamic-memory-allocation","first-come-first-serve","min-heap","nice","red-black-tree","round-robin-scheduler","standard-template-library","static-priority-scheduling","time-slicing","turn-around-time"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imsatyasaiteja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-26T07:07:39.000Z","updated_at":"2024-12-19T13:04:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"eccf0a36-eaf3-4ceb-92d1-a0202d57cf4f","html_url":"https://github.com/imsatyasaiteja/Cpu-Scheduling","commit_stats":null,"previous_names":["imsatyasaiteja/cpu-scheduling"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/imsatyasaiteja/Cpu-Scheduling","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsatyasaiteja%2FCpu-Scheduling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsatyasaiteja%2FCpu-Scheduling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsatyasaiteja%2FCpu-Scheduling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsatyasaiteja%2FCpu-Scheduling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imsatyasaiteja","download_url":"https://codeload.github.com/imsatyasaiteja/Cpu-Scheduling/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsatyasaiteja%2FCpu-Scheduling/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34174148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["completely-fair-scheduler","cpu-scheduling-algorithms","dynamic-memory-allocation","first-come-first-serve","min-heap","nice","red-black-tree","round-robin-scheduler","standard-template-library","static-priority-scheduling","time-slicing","turn-around-time"],"created_at":"2024-11-10T16:14:25.780Z","updated_at":"2026-06-10T22:31:30.184Z","avatar_url":"https://github.com/imsatyasaiteja.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cpu Scheduling\n\nA C++ Program that can create an array of processes, assign random arrival time and burst time, perform Cpu Scheduling based on the user input, and finally output a text file that contains the completion time, turn around time, waiting time and response time for the processes.\n\n## Code Explanation\n\n- A class Process is declared. This contains the Process Id, Arrival Time, Burst Time, Completion Time, \nTurn Around Time, Waiting Time, Response Time, Virtual Run Time, Time Slice, Static Priority. It has \na constructor that takes Process Id, Arrival Time, Burst Time and Nice as it's input arguments. \nIt also has necessary Member functions.\n        \n- A class Process_Creator is declared. This contains an vector which holds objects of the class Process. \nThis vector is created dynamically using new. I named it as \"array\".\n\n- The default constructor of Process_Creator contains a for loop to assign Arrival Time, Burst Time and \nNice values to each process. To assign random values mt19937 has been used.\n\n- A class MinHeap is declared. This contains a pointer to vector of type Process and necessary member \nfunctions like MinHeapify, Build Min Heap, Get Min, Pop.\n    \n- Next a compare function is delcared. This is used while comparing the virtual run times of processes \nin case of Completely Fair Scheduler.\n\n- A class Scheduler is declared. This contains a dynamic vector pointer of type Process. This is our \nready queue. All Processes created by the Process_Creator and stored in it's array are pushed into the \nready queue according to the Scheduling algorithm. Scheduler constructor takes the address of a \nProcess_Creator Object as parameter. This constructor makes it's private data member array pointer to \npoint towards the address of Dynamically created array of Processes in the Process_Creator's object.\nThis class also contains the fcfs, rr, cfs member functions. They take the running queue as input \nparameter and push the appropriate processes from ready queue to running queue accordingly.\n\n- Simulator class contains a dynamic vector pointer of type Process. This is our running queue. It also \nhas array and ready queue pointers. These two will be used to access the locations of array and ready \nqueue created by other class objects. Also sch is a pointer to Scheduler object is declared. This \npointer location is set in the Simulator constructor and I will be using this to access the fcfs, rr,\ncfs, member functions when needed. \nSimulator class also has Run, runFCFS, runCFS, runRR, CaptureValues, printProcesses member functions.\n\n\n- runFCFS Algorithm :\nMinheap is performed on the processes array. The process with minimum arrival time is kept at the top\nof the min-heap. \nSometimes the processes may not arrive at 0 milliseconds, so the currentTime is equated to the process\nwith minimum arrival time.\nNext, we run a while loop till simulation time. In this loop the following things are done.\nAnother while loop is run. In this, we check the processes whose arrival time is less than current time \nand push them in a sequential order into the ready queue, and pop out from the array.\nNext we pass running queue as pass by reference into fcfs function present in the scheduler class. This \nfcfs function, has access to the ready queue. So, it pushes the first process into running queue and\nremoves it from ready queue. Now, the Response time, Completion time are set.\nThis loop runs till the processes array and ready queue become empty and all processes go into the running\nqueue.\n\n- runRR Algorithm :\nMinheap is performed on the processes array. The process with minimum arrival time is kept at the top\nof the min-heap.\nSometimes the processes may not arrive at 0 milliseconds, so the currentTime is equated to the process\nwith minimum arrival time.\nNext, we run a while loop till simulation time. In this loop the following things are done.\nAnother while loop is run. In this, we check the processes whose arrival time is less than current time \nand push them in a sequential order into the ready queue, and pop out from the array.\nWe check if the running is not empty and the last process with non zero left burst time is kept back in\nthe ready queue.\nNext we pass running queue as pass by reference into rr function present in the scheduler class. This \nrr function, has access to the ready queue. So, it pushes the first process of ready queue into running \nqueue and removes it from ready queue. The Response time is set.\nNext, we update the left burst time, current time of the last process in running queue.\nThis loop runs till the processes array and ready queue become empty and all processes go into the running\nqueue. \n   \n- runCFS Algorithm :\nMinheap is performed on the processes array. The process with minimum arrival time is kept at the top\nof the min-heap.\nSometimes the processes may not arrive at 0 milliseconds, so the currentTime is equated to the process\nwith minimum arrival time.\nNext, we run a while loop till simulation time. In this loop the following things are done.\nAnother while loop is run. In this, we check the processes whose arrival time is less than current time \nand push them in a sequential order into Red Black Tree and pop out from the array.\nHere Red Black Tree is implemented using map STL. In this Red Black Tree the processes are placed as per \ntheir virtual run times (if they are equal, then nice values, followed by arrival time, and then by \ncomparision between process Ids)\nWe check if the running is not empty and the put last process with non zero left burst time back in the \nready queue.\nThe process with minimum virtual run time is kept at the left most position of the red black tree. We use \nit-\u003efirst to point to this process with minimum virtual runtime. This process and the running queue are \npassed into the cfs function of schedular class.\nThis cfs function in scheduler class pushes the process into running queue and sets its response time.\nNext we fix the virtual run time of the process in running queue. Note that the formula used in the code \nis empirical and derived taking the real formuals into consideration.\nAfter setting the virtual run time, we update the left burst time and current time.\nThis loop runs till the processes array and ready queue become empty and all processes go into the running\nqueue.\n\n- Status.txt is obtained when the run codes of scheduling algorithms start running.\n\n- Next we have callAlgo function which creates Process_Creator object obj, Scheduler object sch, Simulator \nobject sim and runs the algorithm as per user's choice and sends the output to processes.txt.\n\n- Main function takes the Number of processes and simulation time in seconds.\n   \n## Resources : \n\n- Round Robin Scheduler learning resource [Youtube video](https://www.youtube.com/watch?v=TxjIlNYRZ5M\u0026t=421s)\n\n- Completely Fair Scheduler learning resource [Slides](https://www.cse.iitd.ac.in/~rijurekha/col788/scheduling1.pdf) and [ Youtube video](https://www.youtube.com/watch?v=MkJfuI5_hjc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimsatyasaiteja%2Fcpu-scheduling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimsatyasaiteja%2Fcpu-scheduling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimsatyasaiteja%2Fcpu-scheduling/lists"}