I wrote a program
#include <stdio.h>
#include <unistd.h>
int main()
{
int returnVal = fork();
printf("Return Value: %i\n", returnVal);
return 1;
}
when I compile this and run, I get the following output
I have given only one printf statement then why do I see 2 prints. If I remove the print then nothing is printed.
alwin@alwin-desktop:~/Projects/Nix$ ./a.out
Return Value: 5547
Return Value: 0
You need to go through man command 🙂
Check:
pid_t fork(void);DETAILS:: First you executed your code which created a child process. Now you have two processes executing the same piece of code. So TWO print statements, first of the Parent Process and second of the Child Process.