Linked Questions
14 questions linked to/from fork() branches more than expected?
27 votes
2 answers
945 views
The behavior of the fork() system call on Linux in this code [duplicate]
I have read in books and online resources that the fork() system call creates a copy of current process and both the processes start executing from the point after the fork() system call is made. Is ...
8 votes
3 answers
303 views
fork is confusing me [duplicate]
Can anyone, please, explain how does this code work ? int main() { printf("Hello"); fork(); printf("World"); } Prints: HelloWorldHelloWorld My exact question is, why hello is printed twice. ...
6 votes
2 answers
240 views
Understanding of Fork in C [duplicate]
I have one problem with fork that i don't undertsand. #include <stdio.h> #include <string.h> main(){ printf("test 1.\n"); fork(); printf("test 2.\n"); ...
0 votes
1 answer
368 views
how many processes are created in this code using fork() [duplicate]
How many processes does the following piece of code create? Why? int main() { fork(); fork(); fork(); return 0; } I was looking for assitance that said build a tree but i came up with 10 ...
0 votes
1 answer
200 views
Forking code creates unexpected results when redirecting output to file [duplicate]
I have the following C code: #include <stdio.h> #include <unistd.h> int main() { int i, pid = 0; for (i = 0; i < 3; i++) { fork(); pid = getpid(); ...
1 vote
0 answers
297 views
understand fork in c [duplicate]
Possible Duplicate: printf anomaly after “fork()” Using fork with c fork() branches more than expected? I have this example of code, but I don't understand why this code print ...
1 vote
1 answer
56 views
Flow of Fork() system call [duplicate]
#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { fork(); printf("hello\n"); fork(); fork(); return 0; } if fork() system call ...
18 votes
5 answers
84k views
How to use Fork() to create only 2 child processes?
I'm starting to learn some C and while studying the fork, wait functions I got to a unexpected output. At least for me. Is there any way to create only 2 child processes from the parent? Here my ...
1 vote
4 answers
3k views
Creation of A New Process in an OS
In the book 'Operating System Concepts' - 9th Edition - Chapter 3 - Page 117 - Page 120 it says: Both processes (the parent and the child) continue execution at the instruction after the fork(), with ...
2 votes
3 answers
555 views
Why does fork() and printf() output more than I predict?
This is my little program: #include <unistd.h> #include <stdio.h> int main() { printf("1"); fork(); printf("2"); fork(); return 0; } The output of this code is 12121212 and I ...
0 votes
1 answer
276 views
C - Creating child processes
How do i create a number of child processes given from command line ? Something like this , where n is given from command line : for (i = 0; i < n; i++) { pids[i] = fork(); }
-2 votes
2 answers
299 views
How many processes, with fork functions?
How many proccesses are created with these fork functions? int main(){ c2=0; c1=fork(); if(c1==0) c2=fork(); fork(); if(c2>0) fork(); } In this site,I have seen ...
1 vote
1 answer
123 views
Why does my forking program double in size after each fork?
So i just want to create a simple forking program that forks 5 children at the rate of 1 per every half second and then displays the date and time when each fork is complete.. so this is the jist of ...
1 vote
2 answers
71 views
Some strange result in fork() sys_call
I have the following code: int main(){ int i = 4, pid; while (--i){ pid = fork(); if (pid || (i&1)) printf ("Boo %d\n", i); } return 0; } I understand the code, but I don't ...