c language wait for the fork child thread to end

c language wait for the fork child thread to end
r‮efe‬r to:lautturi.com
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/unistd.h>

int main(){
    pid_t pid = fork();
    if (pid == 0) {
        printf("child process \n");
        exit(12);
    } else {
        int child_status;
        printf("Parent Process\n");
        waitpid(pid, &child_status, 0); // Wait for the child process to finish
        printf("Results returned by subprocess: %d\n", WEXITSTATUS(child_status));
    }
    printf("Bye\n");
    return 0;
}
Created Time:2017-08-29 12:58:01  Author:lautturi