Dummy commit to test new ssh key
[eleutheria.git] / ipc / fork_execlp.c
blob2bffc3ae97312f23fbc77395e91d048755c1d52c
1 /*
2 * Compile with:
3 * gcc fork_execlp.c -o fork_execlp -Wall -W -Wextra -ansi -pedantic
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/wait.h>
11 int main(void)
13 pid_t pid;
14 int retval;
16 if ((pid = fork()) < 0) { /* fork error */
17 perror("fork()");
18 exit(EXIT_FAILURE);
21 else if (pid > 0) /* parent process */
22 wait(&retval);
24 else { /* child process (pid = 0) */
25 if (execlp("date", "date", (char *)0) < 0) {
26 perror("execlp()");
27 exit(EXIT_FAILURE);
32 * Whatever goes here, will be executed from the
33 * parent AND the child process as well
36 return EXIT_SUCCESS;