Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/wait.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdbool.h>
  10.  
  11. int main()
  12. {
  13.     pid_t wpid;
  14.     int status = 0;
  15.     bool exit = false;
  16.     while (exit == false){
  17.         char command[50];
  18.         printf(">");
  19.         fgets(command, 50, stdin);
  20.         if (strcmp("exit\n",command) != 0) {
  21.             int i = 0;
  22.             char *pointer = strtok (command, " \n");
  23.             char *tokens[15];
  24.  
  25.             while (pointer != NULL)
  26.             {
  27.                 tokens[i++] = pointer;
  28.                 pointer = strtok (NULL, " \n");
  29.             }
  30.             tokens[i] = NULL;
  31.             int make_fork = fork();
  32.             if (make_fork == 0) {
  33.                 execvp(tokens[0],tokens);
  34.             }
  35.             while ((wpid = wait(&status)) > 0);
  36.         }
  37.         else {
  38.             exit = true;
  39.         }
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement