From 99664f595d41afc2a23c7fa06904892f102df70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cchenyue=E2=80=9D?= <10195501438@stu.ecnu.edu.cn> Date: Sat, 13 Mar 2021 00:44:19 +0800 Subject: [PATCH] 3.12 commit --- fun_1.c | 16 ++++++++++++++-- fun_2.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- main | Bin 23064 -> 23680 bytes 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/fun_1.c b/fun_1.c index 5a0a413..02ae6ad 100644 --- a/fun_1.c +++ b/fun_1.c @@ -2,6 +2,8 @@ #include #include #include +#include + //#include "fun.h" @@ -22,6 +24,10 @@ void eval(char *cmdline) { if((pid=fork())==0) { + if(isBg) + { + signal(SIGCHLD, SIG_IGN); + } if(execvp(argv[0],argv)<0) { printf("%s:Command not found.\n",argv[0]); @@ -30,10 +36,12 @@ void eval(char *cmdline) } if(!isBg) { - wait(NULL); + wait(0); + return; } else { + signal(SIGCHLD, SIG_IGN); return; } } @@ -86,7 +94,7 @@ int parseline(const char *cmdline, char **argv) argv[argc] = NULL; if (argc == 0) - return 1; + return 1; if ((bg = (*argv[argc-1] == '&')) != 0) { @@ -101,6 +109,10 @@ int builtin_cmd(char **argv) { return 1; } + if(Is_open(argv)==1) + { + return 1; + } if(!strcmp(argv[0],"quit")||!strcmp(argv[0],"exit")) { exit(0); diff --git a/fun_2.c b/fun_2.c index 9afceea..52d0b77 100644 --- a/fun_2.c +++ b/fun_2.c @@ -1,4 +1,5 @@ #include +#include //#include "fun.h" static int num = 0; @@ -93,4 +94,63 @@ void shell_pip(char **prog1, char **prog2) wait(0); wait(0); return 0; -} \ No newline at end of file +} + +int Is_open(char **argv) +{ + int i = 0; + int Isopen = 0; + char *cmd_0[MAXLINE]; + char *cmd_1[MAXLINE]; + while (argv[i]!=NULL) + { + if (argv[i][0] == '>') + { + Isopen = 1; + } + i++; + } + if(Isopen == 0) + { + return 0; + } + i = 0; + while (argv[i][0] != '>') + { + cmd_0[i] = argv[i]; + i++; + } + cmd_0[i] = NULL; + i++; + int j = 0; + while (argv[i]!=NULL) + { + cmd_1[j] = argv[i]; + i++; + j++; + } + cmd_1[j] = NULL; + shell_open(cmd_0, cmd_1); + return 1; +} + +void shell_open(char **prog1, char **prog2) +{ + //根据解析命令参数,创建/打开一文件 + int fd; + if(fork() == 0) + { + if( (fd=open(prog2[0],O_RDWR | O_CREAT | O_NOCTTY | O_NDELAY))<0 ) + { + perror("open"); + exit(0); + } + close(1); + dup(fd); + close(fd); + execvp(prog1[0], prog1); + exit(1); + } + wait(0); +} + diff --git a/main b/main index c70b2b22cf645342dea409640fa56df9491ab596..e9cf204111f89d8372e26b0a2354076c66ddeb6c 100755 GIT binary patch delta 7941 zcmb7JdsI|Mny8786bc>RR4^UKmp*9HG5FaQS(L6*WiW#D~LN=0d+K9Lk zLju<5Boi~DJ2B3VbCv|h(M%#3ooF7LQO_C2jgwuS(HxBK9DF2$O49p%b?dg!`p?uk zU0?macRg-Z-P^Apq#KXWX78ijrXazh)`WDHa>%P78Ba_g8AQ@rrnZ>dysD_p+wx^5 zJ;+S-wSj}(DsQkm$Qv5ntg^{wc7%TB`*8EK3+tLzU%o}kUMk%>M)!+B6+0!+@Upig zj}hIjT(C5OouMhTmD%GwtXuNZEH+S=MN8QY$wO)U^U~#9yBb=baak+0#&C-X>`dHL{kl~vS1+w%HaRbDO?Aa;Hb;Jq z{YAF0ujMrQQ)bdnqc%26@A0`rr;v08$~lsu_O@@(`zf`uw+u^YBKzLpVZ8=RxK*ea zKt&7_H`(8Z@8KM^x@Akf8>+u<3~iI=dIBWW&{-ozPKWAG7>{#>$k=(nj-=0r+U5^J z3vngNu3n5lNiRlB5uc7k!obK!29EUAPOdN!u?}$?$JvPE5VvwX6ft(`YBR@ai1mm! za-4)1`*XFLV+Ud*;&P77h)sw~Fn%OmLWUU`L9TGu4Ol@ulH;3*ErZ|JX4czBS-%edV*n|yNA83@p3!h9~ArroL_5J`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