<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; process duplication</title>
	<atom:link href="https://www.emblogic.com/blog/tag/process-duplication/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Process Duplication using fork</title>
		<link>https://www.emblogic.com/blog/01/process-duplication-using-fork/</link>
		<comments>https://www.emblogic.com/blog/01/process-duplication-using-fork/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 10:28:24 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[process duplication]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13158</guid>
		<description><![CDATA[Process Duplication using system call fork ============================== - A new process is created using fork(). - fork() is a system call. - fork duplicates the current process. - It creates a new entry in the process table with many of &#8230; <a href="https://www.emblogic.com/blog/01/process-duplication-using-fork/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Process Duplication using system call fork<br />
==============================<br />
- A new process is created using fork().<br />
- fork() is a system call.<br />
- fork duplicates the current process.<br />
- It creates a new entry in the process table with many of same</p>
<p>attributes as current process.<br />
- The new process (known as child process) is almost identical to</p>
<p>original process (known as parent process).<br />
- PPID (Parent Process Identification) of new process is PID of</p>
<p>original process.<br />
- PID (Process Identification) of new process is lowest PID</p>
<p>available after the PID of original process .Mostly it is 1 greater</p>
<p>than the original process(If available).<br />
- Prototype of fork :-<br />
pid_t fork(void);<br />
- Function fork() is declared in header:<br />
#include&lt;unistd.h&gt;<br />
- It has a return type pid_t .<br />
- System type pid_t is declared in header :<br />
#include&lt;sys/types.h&gt;<br />
- The Process counter of new process starts from fork() statement.<br />
- So, fork() is executed twice.<br />
- When fork() is executed by parent, it returns PID of child</p>
<p>process on success.<br />
- When fork() is executed by child, it returns 0 for success.<br />
- If fork fails, it returns -1.<br />
- Falure may be due to :-<br />
* Limit on the number of child processes that a parent may</p>
<p>have (CHILD_MAX), in which errno will be set to &#8220;EAGAIN&#8221;</p>
<p>* If process table or virtual memory is filled (not enough</p>
<p>space), errno variable will be set to &#8220;ENOMEM&#8221;.<br />
- The return value of fork() can be used to determine whether child</p>
<p>or parent is executing.<br />
- For eg. :-<br />
#include&lt;stdio.h&gt;<br />
#include&lt;unistd.h&gt;<br />
#include&lt;sys/types.h&gt;<br />
int main()<br />
{<br />
pid_t fret;<br />
printf(&#8220;Only parent execute\n&#8221;);<br />
fret = fork();//Fork statement<br />
printf(&#8220;Both parent and child execute this statement.\n&#8221;);<br />
switch(fork)<br />
{<br />
case -1 :<br />
perror(&#8220;fork&#8221;);<br />
exit(EXIT_FAILURE);<br />
break;<br />
case 0 :<br />
printf(&#8220;Child executing\n&#8221;);<br />
break;<br />
default :<br />
printf(&#8220;Parent executing\n&#8221;);<br />
break;<br />
}<br />
return 0;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/process-duplication-using-fork/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
