// kompilacia: gcc -o priklad12 priklad12.c #include #include #include #include #include #include int main () { int pid; pid = fork(); if (pid == -1) { perror("fork"); exit(EXIT_FAILURE); } if (pid == 0) { // dcersky proces - pockame 5 sekund sleep(5); // a spustime ping neexistujucihost char * args[] = {"ping", "neexistujucihost", NULL}; execvp("ping", args); // ak sa execvp nepodarilo, vratime hodnotu 50 exit(50); } // rodicovsky proces int status; waitpid(pid, &status, 0); if (WIFEXITED(status)) { printf("dcersky proces skoncil s navratovou hodnotou %i\n", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { printf("dcersky proces bol terminovany signalom cislo %i\n", WTERMSIG(status)); } else if (WCOREDUMP(status)) { printf("dcersky proces vyprodukoval core dump\n"); } else if (WIFSTOPPED(status)) { printf("dcersky proces bol stopnuty signalom cislo %i\n", WSTOPSIG(status)); } exit(EXIT_SUCCESS); }