{"id":342,"date":"2025-11-13T03:26:46","date_gmt":"2025-11-13T03:26:46","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=342"},"modified":"2025-12-19T04:30:53","modified_gmt":"2025-12-19T04:30:53","slug":"round-robin-rr-scheduling-algorithm","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=342","title":{"rendered":"Round Robin (RR) Scheduling Algorithm"},"content":{"rendered":"\n<p><strong>Definition:<\/strong><br>Round Robin is a <strong>preemptive CPU scheduling algorithm<\/strong> where <strong>each process is assigned a fixed time slice or quantum<\/strong>. The CPU executes each process for this fixed amount of time in a cyclic order. If a process does not finish in its time quantum, it is moved to the end of the ready queue.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Key Features:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Type:<\/strong> Preemptive scheduling<\/li>\n\n\n\n<li><strong>Basis:<\/strong> Time-sharing system<\/li>\n\n\n\n<li><strong>Queue type:<\/strong> FIFO (First In First Out)<\/li>\n\n\n\n<li><strong>Preemption:<\/strong> Occurs after a fixed time quantum expires<\/li>\n\n\n\n<li><strong>Fairness:<\/strong> Every process gets equal CPU time turn by turn<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Working of Round Robin:<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>All processes are kept in a <strong>ready queue<\/strong>.<\/li>\n\n\n\n<li>Each process gets the CPU for a <strong>fixed time quantum (say 4 ms)<\/strong>.<\/li>\n\n\n\n<li>If a process completes within the time quantum, it leaves the CPU.<\/li>\n\n\n\n<li>If not, it is <strong>preempted<\/strong> and moved to the <strong>end of the ready queue<\/strong>.<\/li>\n\n\n\n<li>The CPU then schedules the next process in the queue.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example:<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Process<\/th><th>Burst Time (ms)<\/th><\/tr><\/thead><tbody><tr><td>P1<\/td><td>10<\/td><\/tr><tr><td>P2<\/td><td>5<\/td><\/tr><tr><td>P3<\/td><td>8<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Time Quantum = 4 ms<\/strong><\/p>\n\n\n\n<p><strong>Execution Order:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>P1 (4) \u2192 P2 (4) \u2192 P3 (4) \u2192 P1 (4) \u2192 P2(1) \u2192 P3 (4) \u2192 p1 (2)\n<\/code><\/pre>\n\n\n\n<p><strong>Gantt Chart:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>| P1 | P2 | P3 | P1 | P2 | P3 | p1\n0    4    8   12   16    17   21   23\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Advantages:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Fairness:<\/strong> Every process gets equal CPU time.<\/li>\n\n\n\n<li><strong>Good for time-sharing systems.<\/strong><\/li>\n\n\n\n<li><strong>No starvation:<\/strong> All processes get a chance to execute.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Disadvantages:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Performance depends on the time quantum:<\/strong>\n<ul class=\"wp-block-list\">\n<li>If <strong>too large<\/strong>, RR \u2192 FCFS (First Come First Serve).<\/li>\n\n\n\n<li>If <strong>too small<\/strong>, too many <strong>context switches<\/strong> (inefficient).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Higher overhead<\/strong> due to frequent context switching.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Applications:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Widely used in <strong>time-sharing<\/strong> and <strong>interactive systems<\/strong> (e.g., modern operating systems).<\/li>\n<\/ul>\n\n\n\n<p>his is a <strong>CPU Scheduling \u2013 Round Robin (RR)<\/strong> problem.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Given<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Time Quantum (TQ) = 3<\/strong><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Process<\/th><th>Arrival Time<\/th><th>Burst Time<\/th><\/tr><\/thead><tbody><tr><td>P1<\/td><td>0<\/td><td>5<\/td><\/tr><tr><td>P2<\/td><td>2<\/td><td>3<\/td><\/tr><tr><td>P3<\/td><td>3<\/td><td>2<\/td><\/tr><tr><td>P4<\/td><td>1<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Order by Arrival Time<\/h2>\n\n\n\n<p>Arrival sequence:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Time 0 \u2192 <strong>P1<\/strong><\/li>\n\n\n\n<li>Time 1 \u2192 <strong>P4<\/strong><\/li>\n\n\n\n<li>Time 2 \u2192 <strong>P2<\/strong><\/li>\n\n\n\n<li>Time 3 \u2192 <strong>P3<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Draw the Gantt Chart (Round Robin, TQ = 3)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Execution Flow<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Time 0\u20133<\/strong> \u2192 P1 executes (remaining burst = 2)<\/li>\n\n\n\n<li><strong>Time 3\u20136<\/strong> \u2192 P4 executes (burst finished)<\/li>\n\n\n\n<li><strong>Time 6\u20139<\/strong> \u2192 P2 executes (burst finished)<\/li>\n\n\n\n<li><strong>Time 9\u201311<\/strong> \u2192 P1 executes (burst finished)<\/li>\n\n\n\n<li><strong>Time 11\u201313<\/strong> \u2192 P3 executes (burst finished)<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Gantt Chart<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>0   3   6   9   11  13\n| P1 | P4 | P2 | P1 | P3 |\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Completion Time (CT)<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Process<\/th><th>Completion Time<\/th><\/tr><\/thead><tbody><tr><td>P1<\/td><td>11<\/td><\/tr><tr><td>P2<\/td><td>9<\/td><\/tr><tr><td>P3<\/td><td>13<\/td><\/tr><tr><td>P4<\/td><td>6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Turnaround Time (TAT)<\/h2>\n\n\n\n<p><strong>TAT = Completion Time \u2212 Arrival Time<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Process<\/th><th>TAT<\/th><\/tr><\/thead><tbody><tr><td>P1<\/td><td>11 \u2212 0 = <strong>11<\/strong><\/td><\/tr><tr><td>P2<\/td><td>9 \u2212 2 = <strong>7<\/strong><\/td><\/tr><tr><td>P3<\/td><td>13 \u2212 3 = <strong>10<\/strong><\/td><\/tr><tr><td>P4<\/td><td>6 \u2212 1 = <strong>5<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Waiting Time (WT)<\/h2>\n\n\n\n<p><strong>WT = Turnaround Time \u2212 Burst Time<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Process<\/th><th>WT<\/th><\/tr><\/thead><tbody><tr><td>P1<\/td><td>11 \u2212 5 = <strong>6<\/strong><\/td><\/tr><tr><td>P2<\/td><td>7 \u2212 3 = <strong>4<\/strong><\/td><\/tr><tr><td>P3<\/td><td>10 \u2212 2 = <strong>8<\/strong><\/td><\/tr><tr><td>P4<\/td><td>5 \u2212 3 = <strong>2<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Final Answer Summary<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">&#x2705; Gantt Chart<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>0 | P1 | 3 | P4 | 6 | P2 | 9 | P1 | 11 | P3 | 13\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">&#x2705; Average Times<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Average Waiting Time<\/strong><br>= (6 + 4 + 8 + 2) \/ 4 = <strong>5<\/strong><\/li>\n\n\n\n<li><strong>Average Turnaround Time<\/strong><br>= (11 + 7 + 10 + 5) \/ 4 = <strong>8.25<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>If you want, I can also:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Explain this <strong>step-by-step in exam writing format<\/strong><\/li>\n\n\n\n<li>Solve it using <strong>FCFS \/ SJF \/ Priority<\/strong> for comparison<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Definition:Round Robin is a preemptive CPU scheduling algorithm where each process is assigned a fixed time slice or quantum. The CPU executes each process for this fixed amount of time in a cyclic order. If a process does not finish in its time quantum, it is moved to the end of the ready queue. Key [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-342","post","type-post","status-publish","format-standard","hentry","category-unix"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342"}],"version-history":[{"count":5,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions\/367"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}