Tag: 父子

waitpid()的示例正在使用中?

我知道waitpid()用于等待进程完成,但是如何才能完全使用它? 在这里我想要做的是,创造两个孩子并等待第一个孩子完成,然后在退出前杀死第二个孩子。 //Create two children pid_t child1; pid_t child2; child1 = fork(); //wait for child1 to finish, then kill child2 waitpid() … child1 { kill(child2) }

如何使用Fork()只创建2个子进程?

我开始学习一些C并且在学习fork时,等待函数我得到了意想不到的输出。 至少对于我来说。 有没有办法只从父级创建2个子进程? 这是我的代码: #include #include #include #include int main () { /* Create the pipe */ int fd [2]; pipe(fd); pid_t pid; pid_t pidb; pid = fork (); pidb = fork (); if (pid < 0) { printf ("Fork Failed\n"); return -1; } else if (pid == 0) { //printf("I'm the child\n"); } else […]