{"id":3764,"date":"2024-02-04T09:56:31","date_gmt":"2024-02-04T04:26:31","guid":{"rendered":"https:\/\/cthecosmos.com\/?p=3764"},"modified":"2024-02-19T11:15:38","modified_gmt":"2024-02-19T05:45:38","slug":"fork-it","status":"publish","type":"post","link":"https:\/\/cthecosmos.com\/?p=3764","title":{"rendered":"FORK IT!"},"content":{"rendered":"\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-7dda714aa8ea58e75afd2614995efbba\" style=\"font-size:17px\">The <strong>fork()<\/strong> system call allows one process, the current running parent process to create a new child process. A duplicate is made of the parent process. The child obtains the exact copies of its parent\u2019s memory segment.When the fork() system call is invoked, a new process is created with an identical memory layout to that of its parent.<br><br>Syntax of fork():<br><br><strong>pid_t fork(void);<\/strong><br><br>In parent, it returns the child\u2019s process ID is returned to the parent and 0 is returned to the child on success or returns -1 on error.<br><br>&nbsp;The execution continues from the point where the fork () is returned. But, it is important to remember that, upon the successful call of the fork function, two processes will be under execution at any given point in time. Note, once the fork is called, both the parent and child a race condition will start where whichever process gets the time slice, gets the CPU. We need to use synchronization techniques if we want to the fork in desired manner.<br><br>The code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"197\" data-attachment-id=\"3768\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3768\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-4.png?fit=975%2C197&amp;ssl=1\" data-orig-size=\"975,197\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-4.png?fit=975%2C197&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-4.png?resize=975%2C197&#038;ssl=1\" alt=\"\" class=\"wp-image-3768\" style=\"width:688px;height:auto\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-c7a17a673a12323bf6150e9bb0de5910\" style=\"font-size:17px\">Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"124\" data-attachment-id=\"3769\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3769\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-5.png?fit=975%2C124&amp;ssl=1\" data-orig-size=\"975,124\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-5\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-5.png?fit=975%2C124&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-5.png?resize=975%2C124&#038;ssl=1\" alt=\"\" class=\"wp-image-3769\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-37641d9422baa1fa182960e0a26d8073\" style=\"font-size:17px\"><strong>As you can see in the below image, the 3402 and 3401 are run by a.out concurrently. This process tree is obtained by running the command ps axjf.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"210\" data-attachment-id=\"3770\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3770\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-6.png?fit=975%2C210&amp;ssl=1\" data-orig-size=\"975,210\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-6\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-6.png?fit=975%2C210&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-6.png?resize=975%2C210&#038;ssl=1\" alt=\"\" class=\"wp-image-3770\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-4fa1ab314f7303086fcd3e9fccf92196\" style=\"font-size:17px\">In Parent&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n #include&lt;stdio.h&gt;\n\n void main()\n {\n     printf(&quot;Printing in Parent, only run once\\n&quot;);\n     printf(&quot;Process ID and parent process ID in parent: %d , %d\\n&quot;,getpid(),getppid());\n     fork();\n     printf(&quot;Process ID and parent process ID in (runs in parent and child): %d , %d\\n&quot;,getpid(),getppid());\n     while(1);\n }\n\n<\/pre><\/div>\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-dbf87880dffd38a883c8b1ea6e13a800\" style=\"font-size:17px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In Child<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; highlight: [8,9,10,11]; title: ; notranslate\" title=\"\">\n #include&lt;stdio.h&gt;\n\n void main()\n {\n     printf(&quot;Printing in Parent, only run once\\n&quot;);\n     printf(&quot;Process ID and parent process ID in parent: %d , %d\\n&quot;,getpid(),getppid());\n     fork();\n     printf(&quot;Process ID and parent process ID in (runs in parent and child): %d , %d\\n&quot;,getpid(),getppid());\n     while(1);\n }\n\n<\/pre><\/div>\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-1f4ea7d0909eec424252bc32b2380589\" style=\"font-size:17px\"><strong>Let us understand how the fork works if called multiple time. In this section of code, we will call the fork line by line.<\/strong><\/p>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-05ff6b550b355fb16209ef68a3e9de60\" style=\"font-size:17px\"><strong>The code:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;stdio.h&gt;\nvoid main()\n{\n    printf(&quot; Started from main, Calling forks\\n&quot;);\n    fork(); \/\/fork1\n    printf(&quot; Fork 1 was called.\\n&quot;);\n    fork(); \/\/fork2\n    printf(&quot; Fork 2 was called.\\n&quot;);\n    fork(); \/\/fork3\n    printf(&quot; Fork 3 was called.\\n&quot;);\n    fork(); \/\/fork4\n    printf(&quot; Fork 4 was called.\\n&quot;);\n    while(1);\n}\n\n<\/pre><\/div>\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-c7a17a673a12323bf6150e9bb0de5910\" style=\"font-size:17px\">Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"356\" height=\"688\" data-attachment-id=\"3774\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3774\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-7.png?fit=356%2C688&amp;ssl=1\" data-orig-size=\"356,688\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-7\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-7.png?fit=356%2C688&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-7.png?resize=356%2C688&#038;ssl=1\" alt=\"\" class=\"wp-image-3774\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-73ef745bbf6ff923e9ceab8ce4954e6c\" style=\"font-size:17px\">It is indeed confusing. Let\u2019s make a tree and see how it works.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"446\" data-attachment-id=\"3775\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3775\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-8.png?fit=1125%2C502&amp;ssl=1\" data-orig-size=\"1125,502\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-8\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-8.png?fit=1000%2C446&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-8.png?resize=1000%2C446&#038;ssl=1\" alt=\"\" class=\"wp-image-3775\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-35e69f531d053c9324efeb0525067bab\" style=\"font-size:17px\">The above tree was made by using the command <strong>ps axjf.<\/strong><br><br>Upon running the program, we see that a total of 16 processes have been created. Check the below image for a detailed analysis of how the fork works for that particular code snippet.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"867\" data-attachment-id=\"3785\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3785\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/fork4_calls.png?fit=4415%2C3830&amp;ssl=1\" data-orig-size=\"4415,3830\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"fork4_calls\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/fork4_calls.png?fit=1000%2C867&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/fork4_calls.png?resize=1000%2C867&#038;ssl=1\" alt=\"\" class=\"wp-image-3785\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-541b164122c9879a521632ce79d19cd4\" style=\"font-size:17px\"><br><br>Let us look at how the fork function call works when called iteratively.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoid main()\n{\n        int i;\n\n        for(i=1;i&lt;=3;i++)\n        {\n                if(fork()==0)\n                {\n                        printf(&quot;Loop %d - PID:%d\\tPPID:%d\\n&quot;,i,getpid(),getppid()  ) ;\n                }\n\n        }\n        while(1);\n}\n\n<\/pre><\/div>\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-82b67257660c0c9fb1b8c30c563e7fdc\" style=\"font-size:17px\">The output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"256\" data-attachment-id=\"3777\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3777\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-10.png?fit=620%2C256&amp;ssl=1\" data-orig-size=\"620,256\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-10\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-10.png?fit=620%2C256&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-10.png?resize=620%2C256&#038;ssl=1\" alt=\"\" class=\"wp-image-3777\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-b737262d727cb9d98b9c8322810b0598\" style=\"font-size:17px\">Using the PS command:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"453\" height=\"328\" data-attachment-id=\"3779\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3779\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-11.png?fit=453%2C328&amp;ssl=1\" data-orig-size=\"453,328\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-11\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-11.png?fit=453%2C328&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-11.png?resize=453%2C328&#038;ssl=1\" alt=\"\" class=\"wp-image-3779\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-0ac7cb6ff0bebc78aadd2dc8e5dc7c22\" style=\"font-size:17px\">It can be visualized as the following diagram.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"749\" data-attachment-id=\"3843\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3843\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-13.webp?fit=1024%2C767&amp;ssl=1\" data-orig-size=\"1024,767\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-13\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-13.webp?fit=1000%2C749&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/image-13.webp?resize=1000%2C749&#038;ssl=1\" alt=\"\" class=\"wp-image-3843\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-a9b6f6453a7cde87a4bb3cfbac1e6186\" style=\"font-size:17px\">When the fork call is made, the kernel creates a text segment for the child process by setting up a set of per-process page table entries. These entries refer to the same virtual memory page frames that are already in use by the parent process. The text segment is designated as a read-only code segment.<br><br>In the case of data, heap, and stack segments, the kernel employs a copy-on-write mechanism. After the fork call, if either the parent or the child process attempts to modify one of these pages that are initially created by the kernel, the kernel intercepts the access and creates a duplicate copy of the page that can be modified. This involves assigning a new page and updating the corresponding page table entry for the child process.<br><br>At this point, the parent and child processes can independently modify their respective private copies of the page without affecting each other. The parent&#8217;s process page is not copied for the child process; instead, it is shared between the parent and the child upon forking. When a process attempts to modify a shared page, a separate copy of the page is created exclusively for that process. This copy-on-write approach ensures that pages are only duplicated when a process actually writes to them, optimizing memory usage.<br><br>By utilizing the fork system call and implementing copy-on-write, the operating system efficiently manages memory resources and allows parent and child processes to safely and independently modify shared and private memory pages as needed.<br><\/p>\n\n\n\n<p class=\"has-white-color has-text-color has-background has-link-color has-medium-font-size wp-elements-486e7799b35920eece0029316d5e98bd\" style=\"background:linear-gradient(135deg,rgb(35,23,11) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%)\">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><strong>An Article by: <\/strong>Yashwanth Naidu Tikkisetty<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-e003e9226e0472b70fa5b8e67181406d\"><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The fork() system call allows a parent process to create a child process with an identical memory layout. The parent receives the child&#8217;s process ID, while the child receives 0. Synchronization techniques are needed for desired forking. Multiple calls to fork() create a complex process tree, managed efficiently through copy-on-write to optimize memory usage.<\/p>\n<a href=\"https:\/\/cthecosmos.com\/?p=3764\" class=\"more-link\">Read More <span class=\"screen-reader-text\">FORK IT!<\/span><\/a>","protected":false},"author":120055267,"featured_media":3841,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false},"categories":[36985,30181,35264203,5495],"tags":[273,772321181,772321193,142396,264,34922710,4525386,34920936],"class_list":{"0":"post-3764","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-c-programming","8":"category-embedded-systems","9":"category-linux-3","10":"category-operating-system","11":"tag-blog","12":"tag-education","13":"tag-embedded-systems","14":"tag-fork","15":"tag-learning","16":"tag-linux-2","17":"tag-system-call","18":"tag-ubuntu-2","20":"fallback-thumbnail"},"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/02\/openacc2-2981521003-e1707023695567.png?fit=454%2C174&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8CiEf-YI","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/3764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/users\/120055267"}],"replies":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3764"}],"version-history":[{"count":14,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/3764\/revisions"}],"predecessor-version":[{"id":3844,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/3764\/revisions\/3844"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/media\/3841"}],"wp:attachment":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}