반응형
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>

int main() {
    pid_t pid;

    switch (pid = fork()){
        case -1 :
            perror("fork");
            exit(1);
            break;
        case 0:
            printf("Childe Process - My PID:%d, My Parent's PID:%d\n", (int)getpid(), (int)getppid());
            break;
        default :
            printf("Parent process - My PID:%d, My Parent's PID:%d, My Child's PID:%d\n", (int)getpid(), (int)getppid(), (int)pid);
            break;
    }

    printf("End of fork\n");
    return 0;
}

+ Recent posts