08/01/27 21:55:48
>>676
showpidがおかしくないか?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid;
int i, status, flg = 0;
for (i = 0; i < 10; ++i) {
if ((pid = fork()) < 0) {
fprintf(stderr, "error\n");
exit(1);
}
if (pid == 0) {
execv("showpid", NULL);
exit(1);
} else {
if (flg == 0) {
flg = 1;
printf("I am a parent with pid = %d.My child is %d.\n",getpid(),pid);
}
waitpid(pid, &status, 0);
}
}
return 0;
}