Add some comments plus fix a possible mem leak
[eleutheria.git] / ipc / fork.c
blob7e020a25f1bb54faac7fce895c76f4a76deab212
1 /*
2 * Compile with:
3 * gcc fork.c -o fork -Wall -W -Wextra -ansi -pedantic
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
10 int main(void)
12 pid_t pid;
14 if ((pid = fork()) < 0) { /* fork error */
15 perror("fork()");
16 exit(EXIT_FAILURE);
19 else if (pid > 0) /* parent process */
20 printf("Parent's pid: %d\n", getpid());
22 else /* child process (pid = 0) */
23 printf("Child's pid: %d\n", getpid());
26 * Whatever goes here, will be executed from the
27 * parent AND the child process as well.
30 return EXIT_SUCCESS;