cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
UNIX/Linux Programming
fork() why the output is "Parent Childe"
fork() why the output is "Parent Childe" ? thanks
Jun 5, 2013 at 2:58pm UTC
Mher Didaryan
(7)
#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;
}
Jun 5, 2013 at 3:59pm UTC
Zhuge
(4664)
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.