Remove bogus else if (...) condition
[eleutheria.git] / ipc / fork.c
blobd0c442f636b3dc23cc3826cc7d95dfb38737357a
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 /* child process (pid = 0) */
21 printf("Child's pid: %d\n", getpid());
23 /* whatever goes here, will be executed from the
24 parent AND the child process as well
26 return EXIT_SUCCESS;