我正在研究使用 fork() exec() wait() 的 ac 程序。第一个进程有这个代码:
int main(int argc, const char * argv[]) {
// insert code here...
int pid = fork();
if(pid == 0){
//we are the child process.
execlp("/Users/matthewdunn/Library/Developer/Xcode/DerivedData/PA2-hekivoaqvsegnggdvcfguasystig/Build/Products/Debug/Checker", "Checker", "1", "5", (char*) NULL);
}else{
//we are the parent process.
printf("Coordinator: forked process with ID ");
printf("%d\n", pid);
printf("Coordinator: waiting for process [");
printf("%d", pid);
printf("]\n");
int status;
waitpid(pid, &status, 0);
int returned = WEXITSTATUS(status);
printf("Coordinator: child process ");
printf("%d", pid);
printf(" returned ");
printf("%d", returned);
printf(".\n"); …Run Code Online (Sandbox Code Playgroud)