Note that there are some explanatory texts on larger screens.

plurals
  1. POprobleme with the trace of Fork()
    text
    copied!<p>I have this example of fork() I need to do a trace!</p> <pre><code>#include &lt;unistd.h&gt; int main(void) { int i; for (i=0; i&lt;3; i++) if (fork()) wait(NULL); return 0; } </code></pre> <p>My solution for to do the trace is, something is wrong, I don't know how to do the trace:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; int main(void) { int i,pid; for(i=0;i&lt;3;i++) { pid=fork(); if(pid&gt;0) ///if is father (true) printf("PID After the fork child === %d &amp; father === %d (i = %d) \n\n",(int)getpid,(int)getppid,i); wait(NULL); printf(" After the wait child=== %d &amp; father=== %d (i = %d)|||\n",(int)getpid,(int)getppid,i); } } </code></pre> <p>This is what i get in the Terminal. I can see clearly that it is not correct, but i don't know how to resolve this problem:</p> <pre><code>PID After the fork child === 134513568 &amp; father === 134513632 (i = 0) After the wait child=== 134513568 &amp; father=== 134513632 (i = 0)||| PID After the fork child === 134513568 &amp; father === 134513632 (i = 1) After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| After the wait child=== 134513568 &amp; father=== 134513632 (i = 1)||| PID After the fork child === 134513568 &amp; father === 134513632 (i = 2) After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| After the wait child=== 134513568 &amp; father=== 134513632 (i = 0)||| PID After the fork child === 134513568 &amp; father === 134513632 (i = 1) After the wait child=== 134513568 &amp; father=== 134513632 (i = 1)||| PID After the fork child === 134513568 &amp; father === 134513632 (i = 2) After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| After the wait child=== 134513568 &amp; father=== 134513632 (i = 1)||| PID After the fork child === 134513568 &amp; father === 134513632 (i = 2) After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| After the wait child=== 134513568 &amp; father=== 134513632 (i = 2)||| </code></pre> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload