last day (14 days later) » 

4:49 AM
0
Q: C - Creating IPC Channel using dup/fork/exec/wait

lampwinsI am creating a simple shell that can handle a single pipe. I am having some issues getting my file descriptors to work here. int child_process_status; int fds[2]; pid_t cpid1, cpid2; pipe( fds ); if ( (cpid1 = fork()) == 0 ) { close(1); /* ...

 
check the return value of pipe
 
Should have mentioned I tried that, it is 0
 
are they valid before dup?
 
What do you mean by valid?
 
I would just try not closing them
 
4:49 AM
You mean the close after dup and before the exec?
 
I mean the close before dup... and maybe the one after
 
But omitting the close(1) will cause the dub to not use stdout's place, right?
 
well you issue is that you are writing to or reading from a "bad" file descriptor
that usually means that it has been closed
so if you can figure out where it is closed, you will be closer to figuring it what the problem is
I am just wondering if dup sets something like {0,1} and you then might not be closing the descriptor you think you are
 
Hmm. I did wonder why it was never inited before pipe
 
and I think that even if you close stdout, it is unlikely that number will ever be given out as a descriptor again
 
4:58 AM
according to the man page on dup, it uses the lowest available position.
 
 
10 hours later…
2:36 PM
which is probably 2-3.. if you want to use stdout or stdin use them, opening a new fd at that index doesn't make it a new fd pointing to one of those...
 

last day (14 days later) »