#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
pid_t child_pid;
switch (child_pid = fork()) {
case -1:
fprintf(stderr, "fork() error\n");
exit(EXIT_FAILURE);
case 0: // parent
printf("I am parent\n");
break;
default: // child
sleep(1);
printf("I am child");
break;
}
exit(EXIT_SUCCESS);
}
output:
I am parent
I am child