retagged by
1,458 views
1 votes
1 votes
int main(void) 
{
	 int var1=100;
	 int pid;
	if(pid==fork())
	 var1=200;
	fork();
	printf("%d",var1);
	return 0;
}

what could be the output ?

a)100 100 200 200

b)200 200 200 200

c)none

retagged by

2 Answers

1 votes
1 votes
100 100 200 200 if in first fork call child  is executed before parent otherwise  answer is  200 200 100 100 (option D)

Related questions

1 votes
1 votes
1 answer
2
0 votes
0 votes
1 answer
4
abhinowKatore asked Jan 13, 2023
1,419 views
int doWork(){ fork(); fork(); printf("Hello world!\n");}int main() { doWork(); printf("Hello world!\n"); exit(0);}