Hello, I'm trying to implement a basic shell in c, and so far i have the basic functions and command line input working great, and the & works find, however I'm trying to get pipes to work, my problem is that I'm getting a SIGPIPE when using the pipes
here is a code snip it:
I've been working on this for days because from what i can tell it should be working fine... but I'm kinda new to some of these things so I'm sure I'm missing it. heck i might be doing this entirely wrong for all i knowCode:/* Fork the process to allow program being executed a new PID and * Protect the integrity of the shell process. */ pid = fork(); pipe(data_pipe); switch (pid) { case -1: /* fork failed. */ perror("fork"); return 0; case 0: /* inside child process. */ close(STDIN_FILENO); dup2(data_pipe[1],STDIN_FILENO); close(data_pipe[0]); //close(data_pipe[1]); // may or may not need to do this... /* creat a new command struct so we dont over write parent * processes shared memory */ struct command_t command2; int lcv = 0; /* Initalize the command structure and allocate into memory */ command2.name = (char*)malloc(MAX_ARG_LEN); command2.argc = 0; command2.opv = (char*)malloc(MAX_ARG_LEN); for(lcv=0; lcv<MAX_ARGS;lcv++) { command2.argv[lcv] = (char*)malloc(MAX_ARG_LEN); } strcat(command->opv,"\n"); // hack job to make parsing work exeCommand(pathv,&command2,&command->opv); default: /* inside parent process. */ close(STDOUT_FILENO); dup2(data_pipe[1],STDOUT_FILENO); close(data_pipe[0]); //close(data_pipe[1]); // may or may not be needed. execvp(command->name,command->argv); }, i didn't want to post here cuz well i wanted to figure it out on my own but after a couple of days i'm starting get sleepy. if all the coded is needed i can post that too...
any help anyone can offer would be much appreciated.



LinkBack URL
About LinkBacks
, i didn't want to post here cuz well i wanted to figure it out on my own but after a couple of days i'm starting get sleepy. if all the coded is needed i can post that too...


