[英]C++ - Use System Calls (fork, exec, wait etc) in Code Blocks
我是C ++的新手,我很難找到一個好的IDE。 現在我有代碼塊,但我不能使用像fork,等等系統調用。
我使用Windows 7。
#include <iostream>
#include <stdlib.h>;
#include <sys/types.h>
#include <unistd.h>
using namespace std;
int main()
{
cout << "I am " << (int) getpid() << endl;
pid_t pid = fork();
cout << "fork returned" << (int) pid << endl;
return 0;
if(pid<0) {
cout << "Failed !" << endl;
exit(3);
}
if(pid == 0) {
cout << "i am the child" << (int) getpid() << endl;
cout << "Child exiting" << endl;
exit(0);
}
if(pid >= 0) {
cout << "i am the parent" << (int) getpid() << endl;
wait(NULL);
cout << "Parent ending" << endl;
}
return 0;
}
我不能包括sys / wait.h錯誤:
錯誤:未在此范圍內聲明fork錯誤:未在此范圍中聲明wait
謝謝你的建議!
我使用Windows 7。
那么你確實要使用POSIX函數。 Windows不是POSIX OS。
您將需要使用Windows API的功能。
獲取項目要求列表,然后研究如何在Windows中實現每個要求。
例如:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.