So I have to find the output of this code which is using the fork() method. I thought the output was 5 \"hello\" s but instead I got 8. Why is that? This is the         
        
Here's what your code is doing:
main->doit()->Fork()->Fork()->printf()->return->printf()->exit()
                |       |
                |       ----->printf()->return->printf()->exit()
                |
                ----->Fork()->printf()->return->printf()->exit()
                        |
                        ----->printf()->return->printf()->exit()
As you can see, you have a total of 8 calls to printf().
It would have been easier for you to see what was going on if you chose to print different strings in your main and doit functions.
Setting breakpoint on each printf() call is another effective strategy for figuring out these kinds of problems.