מערכות הפעלה מערכות הפעלה

לחץ כאן לכל השאלות

What is the output of following code? #include <stdio.h> #include <unistd.h> int main() { if (fork()) { if (!fork()) { fork(); printf("1 "); } else { printf("2 "); } } else { printf("3 "); } printf("4 "); return 0; }

1
done
1. It will create two process one parent P (has process ID of child process) and other is child C1 (process ID = 0). 2. When condition is true parent P executes if statement and child C1 executes else statement and print 3. Parent P checks next if statement and create two process (one parent P and child C2). In if statement we are using not operator (i.e, !), it executes for child process C2 and parent P executes else part and print value 2. Child C2 further creates two new processes (one parent C2 and other is child C3).
by
מיין לפי

* השאלה נוספה בתאריך: 20-07-2020