|
@ -2,6 +2,8 @@ |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
#include <wait.h> |
|
|
#include <wait.h> |
|
|
|
|
|
#include <signal.h> |
|
|
|
|
|
|
|
|
//#include "fun.h" |
|
|
//#include "fun.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -22,6 +24,10 @@ void eval(char *cmdline) |
|
|
{ |
|
|
{ |
|
|
if((pid=fork())==0) |
|
|
if((pid=fork())==0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if(isBg) |
|
|
|
|
|
{ |
|
|
|
|
|
signal(SIGCHLD, SIG_IGN); |
|
|
|
|
|
} |
|
|
if(execvp(argv[0],argv)<0) |
|
|
if(execvp(argv[0],argv)<0) |
|
|
{ |
|
|
{ |
|
|
printf("%s:Command not found.\n",argv[0]); |
|
|
printf("%s:Command not found.\n",argv[0]); |
|
@ -30,10 +36,12 @@ void eval(char *cmdline) |
|
|
} |
|
|
} |
|
|
if(!isBg) |
|
|
if(!isBg) |
|
|
{ |
|
|
{ |
|
|
wait(NULL); |
|
|
|
|
|
|
|
|
wait(0); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
|
|
|
signal(SIGCHLD, SIG_IGN); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -86,7 +94,7 @@ int parseline(const char *cmdline, char **argv) |
|
|
argv[argc] = NULL; |
|
|
argv[argc] = NULL; |
|
|
|
|
|
|
|
|
if (argc == 0) |
|
|
if (argc == 0) |
|
|
return 1; |
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
if ((bg = (*argv[argc-1] == '&')) != 0) |
|
|
if ((bg = (*argv[argc-1] == '&')) != 0) |
|
|
{ |
|
|
{ |
|
@ -101,6 +109,10 @@ int builtin_cmd(char **argv) |
|
|
{ |
|
|
{ |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
if(Is_open(argv)==1) |
|
|
|
|
|
{ |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
if(!strcmp(argv[0],"quit")||!strcmp(argv[0],"exit")) |
|
|
if(!strcmp(argv[0],"quit")||!strcmp(argv[0],"exit")) |
|
|
{ |
|
|
{ |
|
|
exit(0); |
|
|
exit(0); |
|
|