1 votes 1 votes How many times the " PROCESS " will be printed when executing the following program? main() { printf(" PROCESS"); fflush(); fork(); fork(); } a) 8 b)4 c)6 d)7 mohitbawankar asked Dec 24, 2017 mohitbawankar 2.0k views answer comment Share Follow See 1 comment See all 1 1 comment reply Sanjay Sharma commented Dec 24, 2017 reply Follow Share 2 fork system calls will produce 3 more child process so total =4 times 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes Answer 4 : fflush() will be necessary to hold the output of the process together or print it when it's necessary(Usually when buff is full). Now each fork() will produce 2 child process. So total no of process will be 22=4. So a total of 4 times "PROCESS" will be printed. Bad_Doctor answered Dec 24, 2017 • edited Dec 24, 2017 by Bad_Doctor Bad_Doctor comment Share Follow See all 3 Comments See all 3 3 Comments reply Sanjay Sharma commented Dec 24, 2017 reply Follow Share what if fflush is removed 0 votes 0 votes Bad_Doctor commented Dec 24, 2017 reply Follow Share Sir I dont think it will make any difference. Then we will assume that output buffer is already empty. :O 0 votes 0 votes Bad_Doctor commented Dec 24, 2017 reply Follow Share I was looking for the reason and i found that printf() is "buffered" it will group the output of a process together and it will print when its necessary(i.e normally when new line is coming or buff is about to flush). 0 votes 0 votes Please log in or register to add a comment.