Reputation: 2697
I try to edit my post, since there were some issues with it.
I am still lost, trying to multipipe my program. When I run the program, goes into a state where it just takes some input - a like, perhaps its because I am not getting input to the second program in my piping process.
I have tried to follow the code from this post: Does this multiple pipes code in C makes sense?
My code looks like this:
int status;
int newpipe[2];
int oldpipe[2];
pid_t pid;
int countcmds = 0;
while (firstCmd != NULL) {
printf("En iteration \n");
if (firstCmd -> next != NULL) {
pipe(newpipe);
}
pid = fork();
if(pid == 0){
if (firstCmd -> prev != NULL) {
dup2(oldpipe[0],0);
close(oldpipe[0]);
close(oldpipe[1]);
}
if (firstCmd -> next != NULL) {
close(newpipe[0]);
dup2(newpipe[1],1);
close(newpipe[1]);
}
char** file = firstCmd -> cmd;
char* specfile = *file;
execvp(specfile, file);
}
else{
waitpid(pid, &status, 0);
if (firstCmd -> prev != NULL) {
close(oldpipe[0]);
close(oldpipe[1]);
}
if(firstCmd -> next != NULL){
oldpipe[0] = newpipe[0];
oldpipe[1] = newpipe[1];
}
countcmds++;
firstCmd = firstCmd -> next;
}
}
if(countcmds){
close(oldpipe[0]);
close(oldpipe[1]);
}
Upvotes: 0
Views: 949
Reputation: 44434
Your execvp(cmd,numberFile);
arguments are way off, the prototype is:
int execvp(const char *file, char *const argv[]);
No idea what your cmd
looks like, but you are supplying an int
for the second parameter.
The execvp
within execute_piping()
also look suspicious, in that you appear to be supplying the complete argument list to the first parameter.
Note: char *argv[]
means that argv
is an array of pointers to char
. I don't see that anywhere, but you should show what structs Cmd
and ShellCmd
are.
I got these warnings from your code:
gash.c:33: warning: passing argument 1 of ‘execvp’ from incompatible pointer type
gash.c:33: warning: passing argument 2 of ‘execvp’ makes pointer from integer without a cast
it is a good idea to fix warnings, warnings are your friends.
Upvotes: 1