c - Could someone explain how fork works? -


i don't understand how fork() works.i understand examples 1 fork,but when there more 1 call don't.i have example , prints 4 lines of hello, how many processes created?

int main(void) {        fork();        fork();        printf("hello\n");         return 0; } 

after fork() call, both processes (original , spawned) continue execute next line of code. both processes execute second fork() instruction, in end have 4 processes. hence see 4 instances of "hello" lines printed.

one picture worth thousand words:

fork illustrated


Comments

Popular posts from this blog

Java 8 + Maven Javadoc plugin: Error fetching URL -

css - SVG using textPath a symbol not rendering in Firefox -

order - Notification for user in user account opencart -