You have already been told that it is wrong to extract the process termination code.
Moreover, your program always forcibly terminates the child process and in status there will always be a signal code - 9 .
Here is a little reworked your program.
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <signal.h> #include <sys/wait.h> int main (int ac, char *av[]) { int status; pid_t pid1, pid2; pid1 = fork(); if (pid1 == 0){ /* proces potomny */ sleep(1); exit(atoi(av[1] ? av[1] : "0")); } /* proces macierzysty */ printf("Ребенок с идентификатором %d\n", (int)pid1); if (av[1] && av[2]) if (kill(pid1, atoi(av[2]))) printf("kill: %m\n"); // some error else printf("send signal %d to child\n", atoi(av[2])); else puts("wait for child exit"); pid2 = wait(&status); int rc = -1; // undefined const char *msg = "exited"; if (WIFEXITED(status)) rc = WEXITSTATUS(status); else if (WIFSIGNALED(status)) { rc = WTERMSIG(status); msg = "terminated"; } else // WIFSTOPPED or WIFCONTINUED msg = "stopped | continued"; printf("Статус окончания процесса %d: 0x%x (%s)\n", (int)pid2, rc, msg); return puts("End") == EOF; }
which in the first argument takes the code with which the child is normally (calling exit() ), and in the second (if specified) the number of the signal that the parent sends to the child.
You can translate (gcc or g ++ if you want) and see its output.
PS
the list of signals can be seen by calling the command kill -l in the shell
and also, an example of the process completion code is given in man 2 wait