From 232c2d5cdb4a07962a6621dd4b8d6680642cf30c Mon Sep 17 00:00:00 2001 From: 10195501441 <10195501441@stu.ecnu.edu.com> Date: Wed, 17 Mar 2021 20:05:19 +0800 Subject: [PATCH] test --- yeeshell | Bin 22824 -> 22776 bytes yeeshell.c | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/yeeshell b/yeeshell index ca41902a771b0234658659210a23799aa10b995e..4c3ecb1479cd236b6d8f4910ca54487c2f85df36 100755 GIT binary patch delta 4899 zcmbVQeQ;FO6~A|r&E_phb~j(Un@zGSAwop537VvQzl1E=Sh1Tz6jU^EMg$5qIDif# zZWNcY-R`jQOgf>}HegX|tp-vxGD;E=0t{`FicX}~hN|O6P@|+ZXk>fNeebOa=AZUv za?ksn-?`_Ud+vSry|)Js^RYubVzc;CWJXQt8GERu=vm`nzR6ina7t8X;J0MF&e z;hF?1AA&D*-O!b2gOdq1XwchWEWyTuU`cetLA{N4LM2{#QNKIU#>dgx%3En9^e1}x zW5P#7^uL2fy_-*ieTi1+(JxPITHkapSd!MjwxoWjHe|XP)8QW%|BRV27i!k^>r)v^ zV5jk#bX#-QOJsQ#S`4$f1ztB;c^15FaC29uKKVY*&9F(T;hFG~^nw49DgSHl&Wp+3 zkbZNai+KY*TXeC0@6I=qkCAT{D|-OdvBE9bo18LU5ne~s@K6j};ReE-aKFI!5T=R^ z_XvDD;RM1R0{@tBBH{K}%#RLkB88q55n)h8IEiqx!1DOyI9)AT|*mxkC0|5~fNI z4+;DUVGH4Yf&WD~op6u9=LlyI?hyEIgfj`ZHweXPQe=@LBJdl8vk5l~e1x!-aFf7? z3EK!OpMA zi+IC}8gZ~UtiPSays<4=xHHPpmUe~|8!|bY$?%ve(Y{pJmt8jla#J0;)B>27nwRk{ zj$m6e>b=2_qT8`%C-fI!edvfvf}^x^x>+J)(bOw2kb1rU#c$Ch z(6cqOy9@J;nh|!BZFDV-4SAy8;EC>!k?Im!AM(mo1Tp#^3F)uL=wTlZW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xyw6)WZA-LH2o32!1r)l!qH?~+9v!T$?kb@Z8iJDYF4>+Q}z0dTiE?us@GRB zm}@y)SM^;WFo@Iaz~~()t5Cj;@;c0f;bgAENlHZd9LgM&w2F74d=l6GVU+*C&HoI_ zGv@<=H&J%uU3na3Bt8blP##2?h$qT`50e~}W_;A#iPDC$o?g+Kp)qkfe;oEE8q9zD zJ`hl2=Ts)+Um^ZAp9%!};fusno(w$6!iyj&$;wwkZjx1X{tT>4O3shOoNU+^%a74* zR~1Bug;;o0cm$(2*a*r6b1lT{`!b&ws_;{hPlx>&@^knC>oB;8^mb>~3xdoh}NeAZJb0ZqD9-w`PxdikN^hdJqY@ln{7ZpEkE8|itx z9ezeTU4%pM^cF^?4W`-cyb_k#tvEjYJOd0RSGQ)E;Kq!ul-uQZ^)<45K$hEO`DYl; zxJ{$H(YHf>ru8ahf)#VZuh6vof{(t6|84%YS(aezBS7egoYxW9on^g@I^WHDo@@GL z@+d+NZ=JnFb5zj?XJrNt!M53!NPmJu%n!4`BUuSiL$WEoU_r^uqzIWl+j)9+sw$Yq zZ=C{6I`XU%DuH^s25Jt;>-rvLHG$!=rlPhu@E1-RES&qWc~mXw1R+-;ES%A5#)m|( zN+C74()xKuv$FnITTfsekU!7J`>~D>iDvDv0g)ee&x^NcS%lo{)jm2_0Rw2Q$GtW% zuL-SJ1usr_(75?P^ zC_f!$KU%j`0w-% zVJV)Q*xD-CCy>>v@CR~cgMSa`pLceZ+BnaEV~g#2{?$H5_4)Y?i{Za(mOb=d~hEvTbixuDwfcvuxn{He-Z|kPWeBl C&{-z{ diff --git a/yeeshell.c b/yeeshell.c index 1114bf2..408f54e 100644 --- a/yeeshell.c +++ b/yeeshell.c @@ -160,6 +160,7 @@ int check_pipe(char **args, char **pipe_arg_1, char **pipe_arg_2) } pipe_arg_1[j++] = args[i++]; } + pipe_arg_1[j] = NULL; j = 0; i++; @@ -167,6 +168,7 @@ int check_pipe(char **args, char **pipe_arg_1, char **pipe_arg_2) { pipe_arg_2[j++] = args[i++]; } + pipe_arg_2[j] = NULL; return pipe_flag; } @@ -245,19 +247,18 @@ int execute(char *cmdline, char **args) else { int fds[2]; + pipe(fds); pid_t prog_1, prog_2; - printf("%s %s %s %s %s %s\n", pipe_arg_1[0], pipe_arg_1[1], pipe_arg_1[3], pipe_arg_1[4], pipe_arg_1[5]); - - printf("%s %s %s %s %s %s\n", pipe_arg_2[0], pipe_arg_2[1], pipe_arg_2[3], pipe_arg_2[4], pipe_arg_2[5]); + printf("%s %s %s %s", pipe_arg_1[0], pipe_arg_1[1], pipe_arg_1[2], pipe_arg_1[3]); if ((prog_1 = fork()) == 0) /* Child process 1 */ { - dup2(fds[1], 1); - dup2(fds[1], 2); + close(1); + dup(fds[1]); close(fds[0]); close(fds[1]); - setpgid(0, 0); + if (execvp(pipe_arg_1[0], pipe_arg_1) <= 0) { printf("%s: Command not found\n", pipe_arg_1[0]); @@ -267,10 +268,11 @@ int execute(char *cmdline, char **args) if ((prog_2 = fork()) == 0) /* Child process 1 */ { + dup2(fds[0], 0); close(fds[0]); close(fds[1]); - setpgid(0, 0); + if (execvp(pipe_arg_2[0], pipe_arg_2) <= 0) { printf("%s: Command not found\n", pipe_arg_2[0]); @@ -281,12 +283,11 @@ int execute(char *cmdline, char **args) close(fds[0]); close(fds[1]); - wait(0); - wait(0); - + waitpid(prog_1, NULL, 0); + waitpid(prog_2, NULL, 0); return 1; } - return 1; + return 0; } int built_in(char **args)