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

int main(void) {
    pid_t pid;

    if ((pid = fork()) == -1) {
        perror("fork");
        return 1;
    }

    if (pid == 0) {
        char* args[] = {"/bin/pwd", NULL};
        execv(args[0], args);

        perror("execv faild"); // if execv returns, means error
        exit(1);
    } else {
        int status;
        wait(&status);

        if (WIFEXITED(status)) {
            printf("child exited with status %d\n", WEXITSTATUS(status));
        } else {
            printf("child exited abnormally\n");
        }
    }

    return 0;
}
