In: Computer Science
Run the following code. Discuss the output result, i.e. the value of seq variable.
#include <stdio.h>
#include <unistd.h>
int main()
{ int seq = 0; if(fork()==0) { printf("Child! Seq=%d\n", ++seq); }
else { printf("Parent! Seq=%d\n", ++seq);
} printf("Both! Seq=%d\n", ++seq); return 0; }
Answer
Given code:
#include<stdio.h>
#include<unistd.h>
int main()
{
int seq = 0;
if(fork()==0) {
printf("Child! Seq=%d\n", ++seq);
}
else
{
printf("Parent! Seq=%d\n", ++seq);
}
printf("Both! Seq=%d\n", ++seq); return 0;
}
Output:
Explanation:
*** please encourage me by your valuable feedback***
thank you......!