Advertisement
Guest User

Untitled

a guest
May 13th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <errno.h>
  5. #include <sys/types.h>
  6. #include <sys/wait.h>
  7. pid_t cree_process(void)
  8. {
  9. pid_t pid;
  10. /* On fork() tant que l'erreur est EAGAIN */
  11. do {
  12. pid = fork();
  13. } while ((pid == -1) && (errno == EAGAIN));
  14. return pid;
  15. }
  16. void fils_process(void)
  17. {
  18. if (execv("/usr/bin/gedit",NULL) == -1) {
  19. perror("execv");
  20. exit(EXIT_FAILURE);
  21. }
  22. }
  23. void pere_process(void)
  24. {
  25. printf("\n gedit est en cours de l'ouverture!\n");
  26. }
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30. pid_t pid = cree_process();
  31.  
  32. switch (pid) {
  33. /* Si on a une erreur irrémédiable (ENOMEM dans notre cas) */
  34. case -1:
  35. perror("fork");
  36. return EXIT_FAILURE;
  37. break;
  38. /* Si on est dans le fils */
  39. case 0:
  40. fils_process();
  41. break;
  42. /* Si on est dans le père */
  43. default:
  44. pere_process();
  45. break;
  46. }
  47. return EXIT_SUCCESS;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement