Hello I am having hard time understanding below code - I tried to break it down and understand it but still no luck -
/* Below code prints 20 times printf */
int main()
{
if (fork() && fork())
{
fork();
}
if (fork() || fork())
{
fork();
}
printf("hello world\n");
return 0;
}
/* If I break and just print AND part - it prints 4 hello world - which kind of makes sense if I assume with AND operation only 1 fork got executed */
int main()
{
if (fork() && fork())
{
fork();
}
printf("hello world\n");
return 0;
}
/* how is the OR operation working - prints 5 Hello World ??*/
int main()
{
if (fork() || fork())
{
fork();
}
printf("hello world\n");
return 0;
}
I have gone through below references from SO site too but still couldnt figure this one out