Untitled

 avatar
unknown
c_cpp
a year ago
546 B
3
Indexable
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
 
int main() {
    printf("ID parent process: %d\n", getpid());
 
    pid_t child_pid = fork();
 
    if (child_pid < 0) {
        perror("fork");
        return 1;
    }
 
    if (child_pid == 0) {
 
        printf("exercise3 %d\n", getpid());
        execlp("uname", "uname", "-a", (char *)NULL);
        perror("execlp");
        _exit(1);
    } else {
 
        int status;
        wait(&status);
        printf("status's child: %d\n", WEXITSTATUS(status));
    }
 
    return 0;
}
Editor is loading...
Leave a Comment