Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/wait.h>
  3. #include <unistd.h>
  4. #include <errno.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <libgen.h>
  8. #include <stdbool.h>
  9.  
  10.  
  11. int main(int argc, char **argv)
  12. {
  13. char input[256];
  14. char *argout[256];
  15. char * pch;
  16. int index;
  17. for(;;){
  18. printf("> ");
  19. fgets(input, sizeof(input),stdin);
  20. index=0;
  21. pch = strtok (input," \n ");
  22. while (pch != NULL){
  23. argout[index]=pch;
  24. index++;
  25. pch = strtok (NULL, " \n ");
  26. }
  27. argout[index]=NULL;
  28. if(strcmp(argout[0],"exit") == 0){
  29. return 0;
  30. }
  31. pid_t fpid;
  32. fpid=fork();
  33. if (fpid==0){
  34. execvp(argout[0],argout);
  35. }
  36. else {
  37. wait(NULL);
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement