Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1.  
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/wait.h>
  8. #include <time.h>
  9. #include <pthread.h>
  10.  
  11. /* Beachten Sie den geaenderten Prototypen von main(). Referenz: man 2 execve */
  12. /* Sie koennen "envp" als Environment-Pointer an Kind-Prozesse weiterreichen. */
  13. int main(int argc, char *argv[], char *envp[])
  14. {   struct timespec before;
  15.     struct timespec after;
  16.  
  17.     pid_t  funktionauslangerung =-1;
  18.  
  19.  
  20.  
  21.     funktionauslangerung = fork();
  22.    
  23.  
  24.     if (funktionauslangerung < 0) {
  25.         perror("FORK ERROR\n");
  26.         exit(EXIT_FAILURE);
  27.     }
  28.  
  29.    
  30.  
  31.     if (funktionauslangerung == 0) {
  32.        
  33.        
  34.        
  35.                
  36.        
  37.        
  38.        
  39.         execve(argv[1], &argv[1],envp);
  40.        
  41.         perror("ERROR");
  42.         exit(EXIT_FAILURE);
  43.  
  44.  
  45.  
  46.  
  47. }
  48. else {
  49.     pid_t child_status = -1;
  50.     //Zeitmessen
  51.     clock_gettime(CLOCK_MONOTONIC, &before);
  52.     waitpid(funktionauslangerung, &child_status, 0);
  53.     clock_gettime(CLOCK_MONOTONIC, &after);
  54.    
  55.    
  56.    
  57.        
  58.  
  59.    
  60.    
  61.     printf("Prozess %ld ends with status  %ld after %ld us\n",
  62.     (long int)funktionauslangerung,child_status,(after.tv_sec-before.tv_sec)*1000);
  63.    
  64.  
  65. ;}
  66.    
  67.  
  68.  
  69.  
  70.  
  71. exit(0);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement