int main(){
char ch;
fork();
cin >> c;
}
After calling fork() I should have 2 exact processes running the same code. Why after running this simple example, I am either asked to enter a character only once, either twice? Shouldn’t the system expect 2 inputs every single time I run this program?
>./a.out
a
>./a.out
a
b
>
You have two processes reading from the terminal at the same time. It is anybody’s guess which process gets the input.
You should not expect consistent behavior if you have two processes reading from the same terminal.