#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
    int *status, wr, pid;
    pid = fork();
    if (pid == -1) {
        perror("fork");
        return 1;
    }
    if (pid == 0) {
        exit(1);
    }

    getchar();
    wr = wait(status);
    if (wr == -1)
        printf("There are no child processes at all\n");
    else {
        printf("Process with pid=%d finished.\n", wr);
        if (WIFEXITED(*status))
            printf("It has exited with code=%d.\n",
                   WEXITSTATUS(*status));
        else
            printf("It was killed by signla %d.\n",
                   WTERMSIG(*status));
    }
    return 0;
}
