Ok, I’m posting my code. I explained things that I want to do before. Posting both my c files, I hope you can find my mistake. Thank you
This is 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;
}
This is 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;
}
./myfork test.c
You might want to test that
execl()doesn’t fail, etc. Aside from some very minor errors you basically had it. The most important thing was to put the parentprintf()after thewaitpid().