nを入力とするn個のプロセスのチェーンを作成し、プロセスの出力は、再帰関数imableを使用して、parent1-> child1(parent2) - > child2(parent3)出力を生成するが、ループを終了することができない場合、ループの中断するnの入力を送信する際にも助けが必要です。n個のサブプロセスのチェーンを作成する
は、以下の私のコードです:
第一:あなたは私はあなたが以下の問題を抱えている理解して言っていることから、
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
int foo(const char *whoami) {
printf("I am a %s. My pid is:%d my ppid is %d\n", whoami, getpid(), getppid());
return 1;
}
int func() {
pid_t pid=fork();
if (pid==0) { /* only execute this if child */
foo("child");
pid_t pid=fork();
if (pid==0) { /* only execute this if child */
foo("child");
func();
exit(0);
}
}
exit(0);
}
wait(0); /* only the parent waits */
return 0;
}
int main(void){
foo("parent");
func();
return 0;
}
また、CまたはC++のいずれかのタグを選択し、その後、Javaのタグを削除してください。 – stijn