fork() why the output is "Parent Childe" ? thanks

#include <sys/types.h>
#include <unistd.h>
#include <iostream>

int main()
{
pid_t pID = fork();

if(pID == 0){
std::cout << "child" << std::endl;
}
if(pID < 0){
std::cout << "failed" << std::endl;
}
if(pID > 0){
std::cout << "parent" << std::endl;
}

return 0;
}
You forked, so now a parent and a child are running. So it makes sense that there is one printing of each. I think you need to put more detail into your question.
Topic archived. No new replies allowed.