{"id":11507,"date":"2022-12-29T10:30:12","date_gmt":"2022-12-29T10:30:12","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=11507"},"modified":"2023-06-08T12:56:24","modified_gmt":"2023-06-08T12:56:24","slug":"round-robin-scheduling-program-in-c","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/","title":{"rendered":"Round Robin Scheduling Program in C"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg\" alt=\"\" \/><\/p>\n<p>What is round-robin scheduling, how is it done, what are its features, what is the round-robin scheduling algorithm with an example, and what is the round-robin scheduling program in C?<\/p>\n<h2>What is round-robin scheduling?<\/h2>\n<p>One of the CPU scheduling strategies is round-robin. The round-robin scheduling algorithm equally distributes each resource and processes each division in a circular sequence without giving any consideration to priority. The terms &quot;time quantum&quot; and &quot;time slice&quot; are used to distribute all resources equally. If a process is finished, it is removed from the ready queue in this round-robin method; otherwise, it will return to the ready queue for the remaining execution. The running queue&#8217;s processes that have arrived and are awaiting execution are in the ready queue. The processes that originated from the ready queue are carried out using the running queue. Let&#8217;s look at the round-robin scheduling method right now.<\/p>\n<h2>Round-robin scheduling algorithm:<\/h2>\n<p>Below are the steps to perform the round-robin scheduling algorithm.<\/p>\n<ul>\n<li>Add all the processes in the ready queue by their arrival time. The ready queue will follow the FIFO structure thus, it will return the first entered process first.<\/li>\n<li>We will now push all the processes in the queue if their arrival time is less than or equal.<\/li>\n<li>After that, we will pop out the first process from the ready queue and push it into the running queue for execution till the fixed time (time quantum).<\/li>\n<li>Now, if the process will be executed completely then we will remove it otherwise we will push it into the end of the ready queue again.<\/li>\n<li>We will now select another process from the ready queue and execute it. If a process finishes its task then we will not push it into the ready queue again as the burst time of the process is completed.<\/li>\n<li>Likewise, we will run all the steps until all the processes are executed.<\/li>\n<\/ul>\n<h3>Round-robin scheduling algorithm with an example.<\/h3>\n<p>Let\u2019s see how the round-robin scheduling algorithm works with an example. Here, we have taken an example to understand the working of the algorithm. We will also do a dry run to understand it better.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972510-Round%20Robin%20Scheduling%20Program%20in%20C1.png\" alt=\"\" \/><\/p>\n<p>In the above example, we have taken 4 processes P1, P2, P3, and P4 with an arrival time of 0,1,2, and 4 respectively. They also have burst times 5, 4, 2, and 1 respectively. Now, we need to create two queues the ready queue and the running queue which is also known as the <strong>Gantt chart.<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972518-Round%20Robin%20Scheduling%20Program%20in%20C2.png\" alt=\"\" \/><\/p>\n<p><strong>Step 1:<\/strong> first, we will push all the processes in the ready queue with an arrival time of 0. In this example, we have only P1 with an arrival time of 0.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972519-Round%20Robin%20Scheduling%20Program%20in%20C3.png\" alt=\"\" \/><\/p>\n<p>This is how queues will look after the completion of the first step.<\/p>\n<p><strong>Step 2:<\/strong> Now, we will check in the ready queue and if any process is available in the queue then we will remove the first process from the queue and push it into the running queue. Let\u2019s see how the queue will be after this step.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972534-Round%20Robin%20Scheduling%20Program%20in%20C4.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have pushed process P1 from the ready queue to the running queue. We have also decreased the burst time of process P1 by 2 units as we already executed 2 units of P1.<\/p>\n<p><strong>Step 3:<\/strong> Now we will push all the processes arrival time within 2 whose burst time is not 0.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972534-Round%20Robin%20Scheduling%20Program%20in%20C5.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have two processes with an arrival time within 2 P2 and P3 so, we will push both processes into the ready queue. Now, we can see that process P1 also has remaining burst time so we will also push process P1 into the ready queue again.<\/p>\n<p><strong>Step 4:<\/strong> Now we will see if there are any processes in the ready queue waiting for execution. If there is any process then we will add it to the running queue.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972540-Round%20Robin%20Scheduling%20Program%20in%20C6.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have pushed process P2 from the ready queue to the running queue. We also decreased the burst time of the process P2 as it already executed 2 units.<\/p>\n<p><strong>Step 5:<\/strong> Now we will push all the processes arrival time within 4 whose burst time is not 0.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972540-Round%20Robin%20Scheduling%20Program%20in%20C7.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have one process with an arrival time within 4 P4 so, we will push that process into the ready queue. Now, we can see that process P2 also has remaining burst time so we will also push process P2 into the ready queue again.<\/p>\n<p><strong>Step 6:<\/strong> Now we will see if there are any processes in the ready queue waiting for execution. If there is any process then we will add it to the running queue.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972540-Round%20Robin%20Scheduling%20Program%20in%20C8.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have pushed process P3 from the ready queue to the running queue. We also decreased the burst time of the process P3 as it already executed 2 units. Now, process P3\u2019s burst time becomes 0 so we will not consider it further.<\/p>\n<p><strong>Step 7:<\/strong> Now we will see if there are any processes in the ready queue waiting for execution. If there is any process then we will add it to the running queue.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972541-Round%20Robin%20Scheduling%20Program%20in%20C9.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have pushed process P1 from the ready queue to the running queue. We also decreased the burst time of the process P1 as it already executed 2 units.<\/p>\n<p><strong>Step 8:<\/strong> Now we will push all the processes arrival time within 8 whose burst time is not 0.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972541-Round%20Robin%20Scheduling%20Program%20in%20C10.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that process P1 also has a remaining burst time so we will also push process P1 into the ready queue again.<\/p>\n<p><strong>Step 9:<\/strong> Now we will see if there are any processes in the ready queue waiting for execution. If there is any process then we will add it to the running queue.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972552-Round%20Robin%20Scheduling%20Program%20in%20C11.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have pushed process P4 from the ready queue to the running queue. We also decreased the burst time of the process P4 as it already executed 1 unit. Now, process P4\u2019s burst time becomes 0 so we will not consider it further.<\/p>\n<p><strong>Step 10:<\/strong> Now we will see if there are any processes in the ready queue waiting for execution. If there is any process then we will add it to the running queue.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972553-Round%20Robin%20Scheduling%20Program%20in%20C12.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have pushed process P2 from the ready queue to the running queue. We also decreased the burst time of the process P2 as it already executed 2 units. Now, process P2\u2019s burst time becomes 0 so we will not consider it further.<\/p>\n<p><strong>Step 11:<\/strong> Now we will see if there are any processes in the ready queue waiting for execution. If there is any process then we will add it to the running queue.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972553-Round%20Robin%20Scheduling%20Program%20in%20C13.png\" alt=\"\" \/><\/p>\n<p>In the above image, we can see that we have pushed process P1 from the ready queue to the running queue. We also decreased the burst time of the process P1 as it already executed 1 unit. Now, process P1\u2019s burst time becomes 0 so we will not consider it further. Now our ready queue is empty so we will not perform any task now.<\/p>\n<p>After performing all the operations, our running queue also known as the <strong>Gantt chart<\/strong> will look like the below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972558-Round%20Robin%20Scheduling%20Program%20in%20C14.png\" alt=\"\" \/><\/p>\n<p>Let\u2019s calculate the other terms like Completion time, Turn Around Time (TAT), Waiting Time (WT), and Response Time (RT). Below are the equations to calculate the above terms.<\/p>\n<p><strong>Turn Around Time = Completion Time &#8211; Arrival Time<\/strong><br \/>\n<strong>Waiting Time = Turn Around Time &#8211; Burst Time<\/strong><br \/>\n<strong>Response Time = CPU first time &#8211; Arrival Time<\/strong><\/p>\n<p>Let\u2019s calculate all the details for the above example.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972558-Round%20Robin%20Scheduling%20Program%20in%20C15.png\" alt=\"\" \/><\/p>\n<h2>Characteristics of round robin scheduling:<\/h2>\n<ul>\n<li>All the processes get an equal share of the CPU.<\/li>\n<li>It is one of the easy scheduling algorithms and it is also easy to implement<\/li>\n<li>It is one of the widely used algorithms for core CPU scheduling.<\/li>\n<li>All the processes get fixed quantum time that&#8217;s why it is preemptive.<\/li>\n<\/ul>\n<h2>Round robin scheduling program in c:<\/h2>\n<p>We have already seen what is round-robin scheduling algorithm and how it works. We will see how to write round robin scheduling program in c. We will use the above algorithm to write the round robin scheduling program in c.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11384 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11384 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11384 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11384 .wpsm_nav-tabs > li.active > a, #tab_container_11384 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11384 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11384 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11384 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11384 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11384 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11384 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11384 .wpsm_nav-tabs > li > a:hover , #tab_container_11384 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11384 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11384 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11384 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11384 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11384 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11384 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11384 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11384 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11384 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11384 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11384 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11384\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11384\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11384_1\" aria-controls=\"tabs_desc_11384_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11384\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11384_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">\/\/ round robin scheduling program in c\r\n#include&lt;stdio.h&gt;   \r\n  \r\nvoid main()  \r\n{    \r\n    int i, NOP, sum=0,count=0, y, quant, wt=0, tat=0, at[10], bt[10], temp[10];  \r\n    float avg_wt, avg_tat;  \r\n    printf(\" Total number of process in the system: \");  \r\n    scanf(\"%d\", &amp;NOP);  \r\n    y = NOP; \r\n    \r\n    for(i=0; i&lt;NOP; i++)  \r\n    {  \r\n        printf(\"&#92;n Enter the Arrival and Burst time of the Process[%d]&#92;n\", i+1);  \r\n        printf(\" Enter Arrival time: &#92;t\"); \r\n        scanf(\"%d\", &amp;at[i]);  \r\n        printf(\" &#92;nEnter Burst time: &#92;t\"); \r\n        scanf(\"%d\", &amp;bt[i]);  \r\n        temp[i] = bt[i]; \r\n    }  \r\n    \r\n    printf(\"Enter the Time Quantum for the process: &#92;t\");  \r\n    scanf(\"%d\", &amp;quant);  \r\n    printf(\"&#92;n Process No &#92;t&#92;t Burst Time &#92;t&#92;t TAT &#92;t&#92;t Waiting Time \");  \r\n    for(sum=0, i = 0; y!=0; )  \r\n    {  \r\n    if(temp[i] &lt;= quant &amp;&amp; temp[i] &gt; 0) \r\n    {  \r\n        sum = sum + temp[i];  \r\n        temp[i] = 0;  \r\n        count=1;  \r\n        }     \r\n        else if(temp[i] &gt; 0)  \r\n        {  \r\n            temp[i] = temp[i] - quant;  \r\n            sum = sum + quant;    \r\n        }  \r\n        if(temp[i]==0 &amp;&amp; count==1)  \r\n        {  \r\n            y--;  \r\n            printf(\"&#92;nProcess No[%d] &#92;t&#92;t %d&#92;t&#92;t&#92;t&#92;t %d&#92;t&#92;t&#92;t %d\", i+1, bt[i], sum-at[i], sum-at[i]-bt[i]);  \r\n            wt = wt+sum-at[i]-bt[i];  \r\n            tat = tat+sum-at[i];  \r\n            count =0;     \r\n        }  \r\n        if(i==NOP-1)  \r\n        {  \r\n            i=0;  \r\n        }  \r\n        else if(at[i+1]&lt;=sum)  \r\n        {  \r\n            i++;  \r\n        }  \r\n        else  \r\n        {  \r\n            i=0;  \r\n        }  \r\n    }    \r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11384 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11384 a\"),jQuery(\"#tab-content_11384\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>Total number of processes in the system: 4\nEnter the Arrival and Burst time of the Process[1]\n Enter Arrival time:    0\n Enter Burst time:  5\n Enter the Arrival and Burst time of the Process[2]\n Enter Arrival time:    1\n Enter Burst time:  4\n Enter the Arrival and Burst time of the Process[3]\n Enter Arrival time:    2\n Enter Burst time:  2\n Enter the Arrival and Burst time of the Process[4]\n Enter Arrival time:    4\n Enter Burst time:  1\n Enter the Time Quantum for the process:    2<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>Process No<\/th>\n<th>Burst Time<\/th>\n<th>TAT<\/th>\n<th>Waiting Time<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Process No[3]<\/td>\n<td>2<\/td>\n<td>4<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>Process No[4]<\/td>\n<td>1<\/td>\n<td>3<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>Process No[2]<\/td>\n<td>4<\/td>\n<td>10<\/td>\n<td>6<\/td>\n<\/tr>\n<tr>\n<td>Process No[1]<\/td>\n<td>5<\/td>\n<td>12<\/td>\n<td>7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Conclusion<\/strong><br \/>\nIn conclusion, the Round Robin scheduling algorithm is a widely used algorithm for process scheduling in operating systems. It is a preemptive algorithm that allocates a fixed time quantum to each process in a circular manner. Round Robin ensures fairness by providing each process with an equal amount of CPU time. This algorithm is easy to implement and guarantees that no process starves CPU time. However, it may not be the most efficient choice for certain scenarios with long-running processes or high context-switching overhead.<\/p>\n<h2>Frequently Asked Questions (FAQs):<\/h2>\n<p><strong>Q1: What is the Round Robin scheduling algorithm?<\/strong><br \/>\nThe Round Robin scheduling algorithm is a preemptive CPU scheduling algorithm used in operating systems. It assigns a fixed time quantum to each process, allowing them to run for that amount of time. Once a time quantum expires, the process is preempted, and the CPU is given to the next process in line.<\/p>\n<p><strong>Q2: How does Round Robin scheduling work?<\/strong><br \/>\nRound Robin scheduling works by maintaining a circular queue of processes. Each process is given a fixed time quantum to execute. When a process&#8217;s time quantum expires, it is moved to the back of the queue, and the next process in line is executed. This process continues until all processes are completed.<\/p>\n<p><strong>Q3: What is the advantage of Round Robin scheduling?<\/strong><br \/>\nThe main advantage of Round Robin scheduling is fairness. Each process is given an equal share of CPU time, preventing any single process from monopolizing the CPU. This ensures that all processes get a chance to execute and avoid starvation.<\/p>\n<p><strong>Q4: Are there any limitations of the Round Robin scheduling algorithm?<\/strong><br \/>\nYes, there are a few limitations of the Round Robin scheduling algorithm. It may not be the most efficient choice when dealing with long-running processes since frequent context switches can introduce overhead. Additionally, if the time quantum is set too short, the performance may be impacted due to frequent process switches.<\/p>\n<p><strong>Q5: Is Round Robin scheduling suitable for real-time systems?<\/strong><br \/>\nRound Robin scheduling is not the ideal choice for real-time systems that require strict timing constraints. This is because Round Robin does not prioritize processes based on their deadlines or priorities. Real-time systems typically employ specialized scheduling algorithms that guarantee the meeting of deadlines and prioritization of critical tasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is round-robin scheduling, how is it done, what are its features, what is the round-robin scheduling algorithm with an example, and what is the round-robin scheduling program in C? What is round-robin scheduling? One of the CPU scheduling strategies is round-robin. The round-robin scheduling algorithm equally distributes each resource and processes each division in [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-11507","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Round Robin Scheduling Program in C<\/title>\n<meta name=\"description\" content=\"Understand round robin scheduling programs in c with round robin scheduling algorithm, characteristic and Examples\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Round Robin Scheduling Program in C\" \/>\n<meta property=\"og:description\" content=\"Understand round robin scheduling programs in c with round robin scheduling algorithm, characteristic and Examples\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-29T10:30:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-08T12:56:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Round Robin Scheduling Program in C\",\"datePublished\":\"2022-12-29T10:30:12+00:00\",\"dateModified\":\"2023-06-08T12:56:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/\"},\"wordCount\":1779,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg\",\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/\",\"name\":\"Round Robin Scheduling Program in C\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg\",\"datePublished\":\"2022-12-29T10:30:12+00:00\",\"dateModified\":\"2023-06-08T12:56:24+00:00\",\"description\":\"Understand round robin scheduling programs in c with round robin scheduling algorithm, characteristic and Examples\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Round Robin Scheduling Program in C\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Round Robin Scheduling Program in C","description":"Understand round robin scheduling programs in c with round robin scheduling algorithm, characteristic and Examples","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Round Robin Scheduling Program in C","og_description":"Understand round robin scheduling programs in c with round robin scheduling algorithm, characteristic and Examples","og_url":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-12-29T10:30:12+00:00","article_modified_time":"2023-06-08T12:56:24+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Round Robin Scheduling Program in C","datePublished":"2022-12-29T10:30:12+00:00","dateModified":"2023-06-08T12:56:24+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/"},"wordCount":1779,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg","articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/","url":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/","name":"Round Robin Scheduling Program in C","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg","datePublished":"2022-12-29T10:30:12+00:00","dateModified":"2023-06-08T12:56:24+00:00","description":"Understand round robin scheduling programs in c with round robin scheduling algorithm, characteristic and Examples","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672308972442-Round%20Robin%20Scheduling%20Program%20in%20C.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/round-robin-scheduling-program-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"Round Robin Scheduling Program in C"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=11507"}],"version-history":[{"count":2,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11507\/revisions"}],"predecessor-version":[{"id":16735,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11507\/revisions\/16735"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=11507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=11507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=11507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}