我想按顺序从孩子到父母打印pid,但与此相反。最后,我想打印主父pid并释放我的表,我该怎么做?请帮我。这是我的简单代码版本:
pid_t pid1, pid2;
pid1 = fork();
if (pid1 == 0) {
printf("%d n", (int)getpid());
execv(argv[0], table);
wait(NULL);
}
if (pid1 > 1) {
pid2 = fork();
printf("%d n", (int)getpid());
if (pid2 == 0) {
execv(argv[0], table);
}
wait(NULL);
}
return(0);