Advertisement
999ms

Untitled

Dec 2nd, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <sys/wait.h>
  7. #include <fcntl.h>
  8.  
  9. int main(int argc, char *argv[], char *envp[]) {
  10. pid_t pid;
  11. int i = 0;
  12. char *env[] = {"LANGUAGE=en_US", NULL};
  13.  
  14. pid = fork();
  15. switch(pid) {
  16. case -1:
  17. perror("fork failed");
  18. exit(1); //выход из родительского процесса
  19. case 0:
  20. execle("/home/sonya/CLionProjects/proc10_1/cmake-build-debug/proc10_1", "l1", "l2", "l3", NULL, env);//int execle (path, arg0, arg1, ..., argn, (char*) 0, envp)
  21. exit(0);
  22. default:
  23. printf("number of arguments: %d\n",argc);
  24. printf("list of arguments: ");
  25. while(argv[i] != NULL)
  26. printf("%s ", argv[i++]);
  27.  
  28. i = 0;
  29. printf("\nenvironment:\n");
  30. while(envp[i] != NULL)
  31. printf("%s\n", envp[i++]);
  32. }
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement