#include <stdio.h>#include <stdlib.h>#include <unistd.h>int main() {
    printf("Before fork (pid:%d)\\n", (int) getpid());
    int rc = fork();
    printf("After fork (pid:%d), rc=%d\\n", (int) getpid(), rc);
    return 0;
}
#include <stdio.h>#include <stdlib.h>#include <unistd.h>int main() {
    printf("Before fork (pid:%d)\\n", (int) getpid());
    int rc = fork();
    printf("After fork (pid:%d), rc=%d\\n", (int) getpid(), rc);
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
    printf("Start (pid:%d)\\n", (int)getpid());
    int rc = fork();

    if (rc < 0) {
        fprintf(stderr, "fork failed\\n");
        exit(1);
    } else if (rc == 0) {
        printf("Child (pid:%d)\\n", (int)getpid());
    } else {
        wait(NULL);
        printf("Parent (pid:%d) - child finished\\n", (int)getpid());
    }
    return 0;
}
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/wait.h>#include <string.h>int main() {
    printf("Starting (pid:%d)\\n", (int)getpid());
    int rc = fork();

    if (rc < 0) {
        fprintf(stderr, "fork failed\\n");
        exit(1);
    } else if (rc == 0) {
        char *args[] = {"ls", "-l", NULL};
        execvp(args[0], args);
        printf("This should not be printed!\\n");
    } else {
        wait(NULL);
        printf("Parent finished (pid:%d)\\n", (int)getpid());
    }
    return 0;
}