Advertisement
Guest User

Simulation de terminal

a guest
Apr 4th, 2010
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. <pre>
  2. #include <stdio.h>
  3. #include <errno.h>
  4.  
  5. #include <unistd.h>
  6.  
  7. int
  8. application(int argc, char* argv[])
  9. {
  10.   char app1[] = "";
  11.   char app2[] = "";
  12.  
  13.   switch (fork())
  14.     {
  15.     case -1 :
  16.       perror("fork : ");
  17.       return 0;
  18.     case 0 :
  19.       if (execvp((argc >= 2) ? app1 : app2, &argv[1]) == -1)
  20.     {
  21.       perror("execvp : ");
  22.       return 0;
  23.     }
  24.       break;
  25.     default :
  26.       wait(NULL);
  27.     }
  28.  
  29.   return 1;
  30. }
  31.  
  32.  
  33. int
  34. main(int argc, char* argv[])
  35. {
  36.   if (argc != 2)
  37.     {
  38.       fprintf(stderr, "Usage...\n");
  39.       return 1;
  40.     }
  41.  
  42.   if (! application(argc, argv))
  43.     {
  44.       return 1;
  45.     }
  46.    
  47.   return 0;
  48. }
  49. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement