Advertisement
Guest User

Untitled

a guest
May 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. void execute_cmd(char * args[], int bg){
  2.  
  3.     /* Relevant für Aufgabe 2 */
  4.     /* clean up children and check if space available */
  5.     if(update_children() >= children_amount){
  6.         printf("Too many processes already running\n");
  7.         return;
  8.     }
  9.  
  10.     /* TODO Your code here -- Aufgabe 1 */
  11.     int pid = fork();
  12.     if(pid == 0) {
  13.         char** argstemp = &args[1];
  14.         execvp(args[0],argstemp);
  15.     }
  16.     else {
  17.         if(!bg) {
  18.             waitpid(pid, NULL, 0);
  19.         }
  20.         else {
  21.             waitpid(pid,NULL, WNOHANG);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement