These are the first two results when I search &quot;fork vs exec&quot; in google.<br><br><br>
<a href="http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html" target="_blank">http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html</a><br>
<a href="http://en.wikipedia.org/wiki/Fork-exec" target="_blank">http://en.wikipedia.org/wiki/Fork-exec</a><br><br>I found very good explanations in both the links(yolinux is a bit better)<br><br>-Sri<br><br><div class="gmail_quote">
On Tue, Feb 7, 2012 at 12:38 AM, Vijay Chauhan <span dir="ltr">&lt;<a href="mailto:kernel.vijay@gmail.com">kernel.vijay@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi List,<br>
<br>
I am learning Linux and trying to understand exec and fork function.<br>
execl says that it overlays the running address space. What does it mean?<br>
<br>
I created the following program and used top command with<br>
intentionally wrong arguments:<br>
<br>
#include&lt;stdio.h&gt;<br>
#include&lt;unistd.h&gt;<br>
#include&lt;sys/types.h&gt;<br>
#include&lt;stdlib.h&gt;<br>
<br>
int main(){<br>
        int a = -1;<br>
        if(fork()==0){<br>
                printf(&quot;Inside child\n&quot;);<br>
                printf(&quot;child pid=%d, parentid=%d\n&quot;, getpid(), getppid());<br>
                execl(&quot;/usr/bin/top&quot;, &quot;/usr/bin/top&quot;, &quot;&gt;/dev/null&quot; ,(char*)0 );<br>
                scanf(&quot;inside child provide a %d&quot;, &amp;a);<br>
                printf(&quot;Inside child a=%d\n&quot;, a);<br>
                exit(1);<br>
        } else {<br>
                printf(&quot;Inside parent, going to wait\n&quot;);<br>
                printf(&quot;my pid=%d, parentid=%d\n&quot;, getpid(), getppid());<br>
                scanf(&quot;input parent %d\n&quot;, &amp;a);<br>
                wait(NULL);<br>
                printf(&quot;Wait over\n&quot;);<br>
                printf(&quot;Inside parent a=%d\n&quot;, a);<br>
        }<br>
        return 0;<br>
}<br>
<br>
When i run this program, it gives following output:<br>
[vijay@localhost]$ ./a.out<br>
Inside parent, going to wait<br>
Inside child<br>
child pid=2775, parentid=2774<br>
my pid=2774, parentid=2681<br>
        top: unknown argument &#39;&gt;&#39;<br>
usage:  top -hv | -bcisSHM -d delay -n iterations [-u user | -U user]<br>
-p pid [,pid ...]<br>
<br>
10<br>
Wait over<br>
Inside parent a=-1<br>
[vijay@localhost]$<br>
<br>
Why the child scanf and printf not executed?<br>
In the parent program, i expected input parent should be printed. But<br>
it doesnt and just wait for some input. When i entered 10 it resumes<br>
but printing -1 as a value.<br>
<br>
Could anyone please help me to understand this behavior? or any good<br>
tutorial or book<br>
<br>
Thanks.<br>
Vijay<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>SK Malik<br>