Initial import of listdir_recursive.c
[eleutheria.git] / ipc / fork.c
blob7f395d18deb835de4a5892ab0b15563def1c7f0c
1 /* compile with:
2 gcc fork.c -o fork -Wall -W -Wextra -ansi -pedantic */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
8 int main(void)
10 pid_t pid;
12 if ((pid = fork()) < 0) { /* fork error */
13 perror("fork");
14 exit(EXIT_FAILURE);
17 else if (pid > 0) /* parent process */
18 printf("Parent's pid: %d\n", getpid());
20 else if (pid == 0) /* child process */
21 printf("Child's pid: %d\n", getpid());
24 /* whatever goes here, will be executed from the
25 parent AND the child process as well
27 return EXIT_SUCCESS;