0 votes 0 votes On Solving manually I too getting 14 as answer. but on running more than 14 * are printed. Operating System operating-system ace-test-series fork-system-call + – Overflow04 asked Aug 29, 2022 Overflow04 864 views answer comment Share Follow See all 7 Comments See all 7 7 Comments reply Show 4 previous comments Arjun commented Aug 31, 2022 reply Follow Share Since the buffer is not emptied in the given code before a call to fork, there is no answer to this question. For those wondering what should be given as answer if this question comes in GATE – GATE questions are made by IIT professors and not by GATE aspirants. But such questions can come for PSU exams and there one can follow any given logic and if your stars match you get correct mark. 1 votes 1 votes afroze commented Sep 1, 2022 i edited by afroze Sep 10, 2022 reply Follow Share Ok bt if use CLR buffer then ans should be 14? 0 votes 0 votes ADITYARAJ commented Feb 28 reply Follow Share correct Ans: 36 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes bcoz not possible to determine order of fork() execution it’s cpu scheduling dependent afroze answered Aug 29, 2022 • edited Aug 29, 2022 by afroze afroze comment Share Follow See all 9 Comments See all 9 9 Comments reply Arjun commented Aug 29, 2022 reply Follow Share Hows CPU affecting fork() execution? 0 votes 0 votes afroze commented Aug 29, 2022 reply Follow Share 😅 edited 0 votes 0 votes Arjun commented Aug 29, 2022 reply Follow Share CPU scheduling can determine the order in which the processes are getting executed and thus the order of print executions. But how can it increase the number of prints? 0 votes 0 votes afroze commented Aug 29, 2022 reply Follow Share It's fine for small inputs, but when I increased them, my logic broke out. 0 votes 0 votes Arjun commented Aug 29, 2022 reply Follow Share Because it has to do with an inherent implementation of printf and fork and not just CPU scheduling. Point 1: printf output is buffered Point 2: Buffer gets copied on fork call So now depending on whether the buffer was emptied or not before fork execution we can get redundant print outputs. 2 votes 2 votes afroze commented Aug 29, 2022 reply Follow Share This means that no other processes should be running when fork() is called. bt how 0 votes 0 votes Arjun commented Aug 29, 2022 reply Follow Share That doesn't mean that. Buffers are private to a given process. 0 votes 0 votes afroze commented Aug 29, 2022 reply Follow Share Ok means wl hv to CLR buffer before every fork() call 0 votes 0 votes Arjun commented Aug 29, 2022 reply Follow Share Yes 1 votes 1 votes Please log in or register to add a comment.
1 votes 1 votes For the child processes pid=0 hence the star in the conditional operator won’t be printed sankalps answered Oct 12, 2022 sankalps comment Share Follow See all 0 reply Please log in or register to add a comment.