Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. char split(char *s) {
  6.  
  7.  char *ss;
  8.  int r = 0;
  9.  int i = 0;
  10.  
  11.  while (s[i] != EOF)
  12.    i++;
  13.  
  14.  int j = 0;
  15.  
  16.  for (j = 0; j < i; j++)
  17.    if (s[j] == '/n' || s[j] == '/t' || s[j] == ' ')
  18.        r = j;
  19.  
  20.  for (j = 0; j < r; j++)
  21.    strcat (ss, s[j]);
  22.    
  23.   return ss;
  24.  
  25. }
  26.  
  27. int main (void) {
  28.  
  29. while (1) {
  30.  
  31. printf ("osh> ");
  32. scanf ("%s", &text);
  33.  
  34. name = split (text);
  35.  
  36. if (strcmp (name , "quit") == 1)
  37.   exit (0);
  38.  
  39. else {
  40.   strcat (history, "|");
  41.   strcat (history, name);
  42. }
  43.  
  44.  pid_t pid;
  45.   int status;
  46.   if ((pid = fork())< 0){
  47.    printf("*** ERROR: forking child process failed\n");
  48.            exit(1);
  49.   }
  50.   else if (pid == 0) {          
  51.          if (execvp(*name, name) < 0) {    
  52.                printf("*** ERROR: exec failed\n");
  53.                exit(1);
  54.          }
  55.      }
  56.      else {                                  
  57.          while (wait(&status) != pid)      
  58.      }
  59.  
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement