Linked Questions

27 votes
2 answers
945 views

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 ...
Akash Mahajan's user avatar
8 votes
3 answers
303 views

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. ...
guitar_geek's user avatar
6 votes
2 answers
240 views

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"); ...
user3234925's user avatar
0 votes
1 answer
368 views

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 ...
user3195820's user avatar
0 votes
1 answer
200 views

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(); ...
derivada's user avatar
1 vote
0 answers
297 views

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 ...
user1479376's user avatar
1 vote
1 answer
56 views

#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { fork(); printf("hello\n"); fork(); fork(); return 0; } if fork() system call ...
Darshan 's user avatar
18 votes
5 answers
84k views

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 ...
mimoralea's user avatar
  • 10.1k
1 vote
4 answers
3k views

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 ...
S. Salman's user avatar
  • 620
2 votes
3 answers
555 views

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 ...
user avatar
0 votes
1 answer
276 views

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(); }
Angelo's user avatar
  • 65
-2 votes
2 answers
299 views

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 ...
user119949's user avatar
1 vote
1 answer
123 views

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 ...
Jeans's user avatar
  • 11
1 vote
2 answers
71 views

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 ...
Mickey's user avatar
  • 500