exec.c
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <sys/wait.h> 5 #include <sys/types.h> 6 7 int main(int argc, char *argv[]) 8 { 9 pid_t pid; 10 11 pid = fork(); 12 if (pid < 0) { 13 fprintf(stderr, "fork failed\n"); 14 exit(1); 15 } 16 17 if(pid == 0) { 18 execlp("ls", "ls", "-a", "-l", (char *) NULL); 19 // pokud exec neselze tento kod se nevykona 20 perror("execl failed"); 21 exit(2); 22 } 23 printf("parent carries on\n"); 24 exit(0); 25 } |