edited by
905 views
1 votes
1 votes
#include <stdio.h>

int main(void) {
    int i=0;
    printf("HAI\n");
    for(i=1;i<=3;i++)
    {
        if(fork()==0)
            printf("*");
    }
    
    return 0;
}

 

How many times * will be printed? and How many times HAI will be printed?

edited by

2 Answers

0 votes
0 votes

Total number of fork() call in parent process =3 (according to loop).

Total number of child processes = 23-1 ; Thus  "*" will be printed 7 times.   HAI will be printed 1 time.

Related questions

0 votes
0 votes
1 answer
1
Erwin Smith asked Apr 11, 2023
781 views
void main() { int n = 1; if(fork()==0) { n = n<<1; printf(“%d, “, n); n = n <<1; } if(fork()==0) n=n+700; printf(“%d, “,n); }Which of the following output is not ...
1 votes
1 votes
2 answers
2
Warrior asked Nov 10, 2018
1,358 views
0 votes
0 votes
0 answers
3