What would be the output? I'm confused, it's 2 or 3 but which one I'm not sure. Can you help?
main()
{
printf("hello\n");
if(fork() == 0)
printf("hello\n");
}
What would be the output? I'm confused, it's 2 or 3 but which one I'm not sure. Can you help?
main()
{
printf("hello\n");
if(fork() == 0)
printf("hello\n");
}
if statement is gonna be evaluated after forking so each process would run it with it's own return value which is zero for child process and non-zero (PID) for parent so there would be 1 hello at this point.
Plus the first hello at the top of your code you get total of 2 hellos at terminal.