479 views
1 votes
1 votes

#include<stdio.h>

int main()

{
fork() && fork ();

printf(“Forked”);

}

 

Explain the output of code with proper reason.

1 Answer

1 votes
1 votes

OUTPUT :

Forked

Forked

Forked

-------------------------------------------------------------------------------------------------

REASON :

First fork() in boolean expression will create a child process with return value of 0, due to which child process won't evaluate condition after &&, will print Forked and exit.

The return value for the above fork() was 1 for parent process, due to which parent process will evaluate condition after &&, which is again fork() creating one more child process. This newly created child process will print Forked and exit.

The parent process too will exit by printing Forked.

Hence the output contains Forked printed thrice. 

 

edited by

Related questions

0 votes
0 votes
1 answer
1
Shivateja MST asked Jul 13, 2023
188 views
Like other allocation techniques, does Overlaying technique uses MMU? And how address translation takes place and security is maintained in Overlaying ?
2 votes
2 votes
2 answers
2
Sunnidhya Roy asked Dec 30, 2022
679 views
Can Safe state in DeadLock Avoidance Mechanism always guarantee No DeadLock??