in Operating System
479 views
1 vote
1 vote
void forkexample() 
{ 
    // child process because return value zero 
    if (fork() == 0) 
        printf("Hello from Child!\n"); 
  
    // parent process because return value non-zero. 
    else
        printf("Hello from Parent!\n"); 
} 
int main() 
{ 
    forkexample(); 
    return 0; 
} 

 

 

 

Please someone explain how things are working?

in Operating System
by
479 views

4 Comments

check the links which is provided in the answer https://gateoverflow.in/242749/self-doubt

1
1
1
1
@shaik, thank you bhai, I'll see those links.
0
0
output will be :

Hello from child!

Hello from parent!

or

Hello from parent!

Hello from child!
1
1

1 Answer

1 vote
1 vote
OUTPUT:

Hello from child!

Hello from parent!

or

Hello from parent!

Hello from child!

Because we dont know wheather parent executed first or child.

Related questions

2 votes
2 votes
2 answers
4