#include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<sys/types.h>#include<sys/wait.h>intmain(int argc, char* argv[]){
int pid = fork();
if (pid == -1) {
return1;
}
if (pid == 0) {
int err = execlp("ping", "ping", "-c", "3", "google.com", NULL);
if (err == -1) {
printf("Could not find program to execute or other error ocurred\n");
return2;
}
} else {
int wstatus;
wait(&wstatus);
if (WIFEXITED(wstatus)) {
int statusCode = WEXITSTATUS(wstatus);
if (statusCode == 0) {
printf("Success\n");
} else {
printf("Failure with status code %d\n", statusCode);
}
}
}
return0;
}
This website uses cookies to ensure you get the best experience on our website. Learn more