2 votes 2 votes 1)Consider the following pseudo code: for(i=1;i<=4;i++) { fork(); printf("X"); } How many times “X” is printed? 2) Consider the following pseudo code: void main() { fork(); fork(); fork(); fork(); printf("X"); } How many times “X” is printed? Operating System fork-system-call operating-system + – ankitgupta.1729 asked Dec 14, 2017 ankitgupta.1729 1.4k views answer comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments Anu007 commented Dec 14, 2017 reply Follow Share fork(); printf("X"); 2 fork(); printf("X"); 4 fork(); printf("X"); 8 fork(); printf("X"); 16 ryt? 1 votes 1 votes ankitgupta.1729 commented Dec 14, 2017 reply Follow Share @Anu and @Abhishek , I am getting 31 now.. processes are created as 1 -->2 --> 4 ---> 8 ----> 16 .. So I am getting 31.. Please correct me.. 0 votes 0 votes akash_chauhan commented Jan 17, 2023 reply Follow Share Bro yu have included an extra 1 at first which I think yu supposed to represent the parent process but, look when that 1 parent process break down to a child and parent process only then it will get printed X Not that primary 1 get printed 0 votes 0 votes Please log in or register to add a comment.
Best answer 3 votes 3 votes for 2 code no of child process=2^n -1=2^4 -1=15 process +1 parent process so total 16 times X will print for 1st code call will be like fork(); printf("X"); 16 fork(); printf("X"); 8 fork(); printf("X"); 4 fork(); printf("X"); 2 print =30 times abhishek tiwary answered Dec 14, 2017 selected Dec 24, 2017 by ankitgupta.1729 abhishek tiwary comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes Part 1-20 times and part 2-16 times neelesh bhakt answered Dec 14, 2017 neelesh bhakt comment Share Follow See 1 comment See all 1 1 comment reply ankitgupta.1729 commented Dec 14, 2017 reply Follow Share Please explain 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes The first code can be simplified as fork(); fork(); fork(); fork(); which is exactly same as the second code. Since there are 4 fork() operation the total process will be 2^n = 16 process DAWID15 answered Dec 16, 2021 DAWID15 comment Share Follow See all 0 reply Please log in or register to add a comment.
–1 votes –1 votes part 1. 64 times part 2 . 16 times Sunit Kumar answered Dec 24, 2017 Sunit Kumar comment Share Follow See 1 comment See all 1 1 comment reply Sona Barman commented Jan 19, 2018 reply Follow Share 64 times for 1 .But how? Pls explain... 0 votes 0 votes Please log in or register to add a comment.