C++-在代码块中使用系统调用(fork、exec、wait等)
C++ - Use System Calls (fork, exec, wait etc) in Code Blocks
我是C++的新手,很难找到一个好的IDE。现在我有代码块,但我不能使用像fork、wait等系统调用。
我用的是Windows7。
#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错误:未在此作用域中声明等待
谢谢你的建议!
我用的是Windows7。
那么使用POSIX函数确实会很困难。Windows不是POSIX操作系统。
您将需要使用Windows API的函数。
列出项目需求,然后研究如何在Windows中实现每一个。
例如:
- windows最接近fork()的东西是什么
相关文章:
- execlp() 在 fork() 之后无法正常工作
- 在 fork() 之后,我在我的程序中不断得到相同的 pid
- OpenSSL C API:如何在程序exec()之后恢复TLS连接?
- Qt/SQL - 从 QSqlQuery exec Stored Procedure 获取列类型和名称?
- Python 的 exec() 函数的 C++ 版本
- 为什么使用 exec() 重新启动程序不能正常工作?
- fork()和exec()两个子进程
- C/C++ linux fork() and exec()
- 在c++中使用popen调用cli实用程序时崩溃.适用于shell或fork、exec等
- Understanding fork, exec, and wait in C++ (Linux)
- C++ : fork/exec or pthread?
- 为什么禁止在 mac 中使用没有 exec 的 fork
- gdb fork() exec on Linux
- C++-在代码块中使用系统调用(fork、exec、wait等)
- 无法在fork-exec之后打开文件
- 使用exec/fork运行外部进程
- 在fork/exec之前分配内存而不释放它安全吗?
- pthread_create b/w fork and exec
- fork exec and mmap issues
- to system() or fork()/exec()?