複数の I/O パイプ (プロセスごとに 1 つのパイプ) を使用して最終結果を取得する mapreduce プログラムを作成しています。プロセスの作成に問題があります。具体的には、次のエラーが発生します。
wait error: Interrupted system call
これはプロセスを生成する私のコードです:
while (values[inc]!=NULL) //provided array of text lines
{
if ((pid = fork()) == -1) {
perror("fork error");
exit(EXIT_FAILURE);
}
else if (pid == 0) { /* start of child process */
printf("Child process...\n");
/* pipes[inc][1] is a file descriptor to which myMap writes some data
using the write() system call
mr is a struct that holds other function pointers */
mr->myMap(pipes[inc][1],values[inc]);
exit(0);
}
else { /* start of parent process */
printf("Parent process...\n");
if ((wpid = wait(&status)) == -1)
/* Wait for child process. */
perror("wait error");
else { /* Check status. */
if (WIFSIGNALED(status) != 0)
printf("Child process ended because of signal %d\n",
WTERMSIG(status));
else if (WIFEXITED(status) != 0)
printf("Child process ended normally; status = %d\n",
WEXITSTATUS(status));
else
printf("Child process did not end normally\n");
}
//close(fd[1]);
printf("Parent process ended\n");
}
inc++;
}
この後、1つのスレッドを作成しています
pthread_t newThread;
pthread_create(&newThread,NULL,threadFunction,values);
pthread_join(newThread,NULL);
threadFunction は select() 関数を使用して、読み取りの準備ができているファイル記述子を見つけ、それを読み取り、データを辞書に入れます。
フォーム gdb デバッガーを実行すると、プログラムは次のように出力します。
Parent process...
Child process...
wait error: Interrupted system call
Parent process ended
Parent process...
Child process ended normally; status = 0
Parent process ended
Parent process...
Child process...
Child process...
wait error: Interrupted system call
Parent process ended
問題を解決する方法がわかりません。助言がありますか?
ありがとう!