I've been attempting to create two children to one parent process using fork(), then running two 'different' commands for those two children. I'm attempting to ping two different websites with these child processes. The thing is when the first ping 'command' is executed it doesn't end, I tried solving this by passing -c amount to limit the amount of outputs, but for some reason it's not doing the job. Here's the code:
pid = fork();
if(pid!=0) {
wait(&status);
printf("----------------------------------------------------\n\n");
printf ( " I am the parent my PID is %d, myPPID is %d, \n ",getpid(),getppid());
printf("---------------------------------------------------\n\n");
}else {
printf ( " I am the child , my PID is %d , my PPID is %d \n",getpid(),getppid());
printf("---------------------------------------------------\n\n");
execl ( "/bin/ping","-c5", "sheffield.ac.uk",(char*)0);
return 0;
if(pid!=0){
printf ( " I am the child , my PID is %d , my PPID is %d \n",getpid(),getppid());
printf("---------------------------------------------------\n\n");
}else {
printf ( " I am the child , my PID is %d , my PPID is %d \n",getpid(),getppid());
printf("---------------------------------------------------\n\n");
sleep(2);
execl ( "/bin/ping","-c5", "shu.ac.uk",(char*)0);
return 0;
}
}
break;