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

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

What is the output of the following code? #include <stdio.h> #include <unistd.h> int main() { if (fork() || fork()) fork(); printf("1 "); 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. In if statement we used OR operator( || ) and in this case second condition is evaluated when first condition is false. 3. Parent process P will return positive integer so it directly execute statement and create two more processes (one parent P and other is child C2). Child process C1 will return 0 so it checks for second condition and second condition again create two more processes(one parent C1 and other is child C3). 4. C1 return positive integer so it will further create two more processes (one parent C1 and other is child C4). Child C3 return 0 so it will directly print 1.
by
מיין לפי

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