Tag:

管道function无法正常执行

我已经构建了以下程序来尝试管道我自己的shell。 StringArray只是我构建的char** 。 代码运行正常,但是当我输入cat txt.txt | grep a cat txt.txt | grep a ,没有任何东西打印回屏幕。 在调试时,我看到代码似乎停止了152(打印输出命令所在的位置),其中pid==0和i==0 。 对于上下文,我在检测到管道后在另一个函数中调用此函数。 void doPipe(StringArray sa) { printf(“In 69\n”); int filedes[2]; // pos. 0 output, pos. 1 input of the pipe int filedes2[2]; int num_cmds = 0; char *command[256]; pid_t pid; int err = -1; int end = 0; // Variables […]

在C中制作shell时管道的正确方法是什么

我正在尝试创建自己的shell我相信我已经正确完成了分叉,但我无法弄清楚如何正确管道。 任何帮助或提示将不胜感激。 基本上我的管道不工作,我花了很多年时间试图弄清楚如何让他们在进程之间正确传输数据。 #include #include #include #include #include #include “ourhdr.h” // from Steven’s book Advanced programing in the UNIX Enviroment extern int makeargv(char *, char * , char ***); int main() { char **argp; int i,j,vpret; char buf[80]; pid_t pid; int pnum; //pipe number int ploc[16]; //pipe location //(this has a max of 12 possible […]