<分区>
好的,我发布我的代码。我之前解释了我想做的事情。发布我的两个 c 文件,我希望你能发现我的错误。谢谢 这是 myfork.c
#include <stdio.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
int pid;
int s;
int waitPid;
int childPid;
pid = fork();
if (pid == 0 && pid != -1) {
childPid = getpid();
printf("Child Process ID:%d, Parent ID:%d, Process "
"Group:%d\n",childPid,getppid(),getgid());
execl("/bin/cat","cat","-b","-t","-v",argv[1],(char*)NULL);
} else {
printf("Original Process ID:%d, Parent Is:%d, Process Group "
"Is:%d\n",childPid,getppid(),getgid());
waitPid = waitpid(childPid,&s,0);
}
return 1;
}
这是test.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(void){
pid_t fork_return;
fork_return = fork();
if (fork_return==0) {
printf("In the CHILD process\n");
} else {
printf("In the PARENT process\n");
}
return 0;
}