.c files don't need to be +x
[eleutheria.git] / ipc / fork_execlp.c
blob8b73372170d125ab27119f420faa3d6fdd9a9d5a
1 /* compile with:
2 gcc fork_execlp.c -o fork_execlp -Wall -W -Wextra -ansi -pedantic */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <sys/wait.h>
9 int main(void)
11 pid_t pid;
12 int retval;
14 if ((pid = fork()) < 0) { /* fork error */
15 perror("fork");
16 exit(EXIT_FAILURE);
19 else if (pid > 0) /* parent process */
20 wait(&retval);
22 else { /* child process (pid = 0) */
23 if (execlp("date", "date", (char *)0) < 0) {
24 perror("execlp");
25 exit(EXIT_FAILURE);
29 /* whatever goes here, will be executed from the
30 parent AND the child process as well */
32 return EXIT_SUCCESS;