Consider the following program snippet. Assume that the program compiles and runs
successfully. Further, assume that the fork() system call is always successful in
creating a process.
int main () {
int i;
for (i = 0; i < 3; i++){
if (fork() == 0){
continue;
}
break;
}
printf("Hello!");
return 0;
}
The total number of times that the printf statement gets executed is ________.
(answer in integer)
The system call fork() creates an exact copy of the calling process. After fork() returns, both the parent and the child resume execution from the very next statement. The return value is what distinguishes them: the child receives \(0\), while the parent receives the child's positive process ID.
The loop under study is:
for (i = 0; i < 3; i++) { if (fork() == 0) { continue; } break; }
So whichever process gets a nonzero return (a parent) immediately executes break and leaves the loop. Whichever process gets \(0\) (a child) executes continue, which increments i and re-checks the loop condition.
Step 2: Trace i = 0 (original process P0)P0 executes fork(), creating a child C1.
C1 executes fork(), creating a child C2.
C2 executes fork(), creating a child C3.
The processes that actually reach the printf() statement are P0, C1, C2 and C3 -- each one exactly once, because a process either breaks right after a fork() call or exits the loop when the condition fails, and in either case it goes straight to printf() without ever calling fork() again.
Total fork() calls \(=3\) (by P0, C1, C2), producing \(3\) new children. Together with the original process P0, there are \(3+1=4\) processes in total, and each executes printf() exactly once.
\[ \text{Total printf() executions} = 4 \]
Final Answer: 4
A schedule of three database transactions \(T_1\), \(T_2\), and \(T_3\) is shown. \(R_i(A)\) and \(W_i(A)\) denote read and write of data item A by transaction \(T_i\), \(i = 1, 2, 3\). The transaction \(T_1\) aborts at the end. Which other transaction(s) will be required to be rolled back?

Identify the ONE CORRECT matching between the OSI layers and their corresponding functionalities as shown.

Consider the following statements:
Which ONE of the following is CORRECT?
Consider the routing protocols given in List I and the names given in List II:

For matching of items in List I with those in List II, which ONE of the following options is CORRECT?