Question

fork(); for(i=0;i<5;i++) if(pid==0)fork(); How many child process are created?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer :

There are total 7 child processes created for the given code

Here is the complete code i executed based on your code to know how many child processes are created:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    int i;
    int pid;
    fork();
    for(i=0;i<5;i++)
    {
        if(pid==0){
            fork();
            printf("child process is created\n");
        }
    }
}

Explanation about how 7 child processes created:

Inorder to know how many child processes created, for that i wrote a print statement as child process is created, i.e, the number of "child process is created " printed in output is equal to number of child processes created.

Output:

child process is created child process is created child process is created child process is created child process is created

Add a comment
Know the answer?
Add Answer to:
fork(); for(i=0;i<5;i++) if(pid==0)fork(); How many child process are created?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT