I'm implementing shell in C and when implementing the redirection operation, I see that the output redirection works fine but the input redirection operation doesn't do anything. (no display is given in the stdout)
COMMAND-> wc < out.txt
Child 12878 died 0x008B
COMMAND->
[where COMMAND-> is my prompt]
When I print the status of the child when it dies, it gets a value of 0x8B. Does this signify anything?
I've followed this post and the core part of the implementation of redirection is similar to what is suggested here. Implementing shell in C and need help handling input/output redirection
This is the gist of what is happening at the input redirection :
in = open(file_name, O_RDONLY);
dup2(in,0);
close(in);
execvp("wc",args);
(I cannot post my entire code since this is a live homework and I might end up caught with MOSS)
SIGSEGV, you have a segmentation fault somewhere,gdbshould be able to tell you more.wcitself is unlikely to segfault even if you gave it invalid file descriptor, the segfault is probably between theforkcall and theexecof the actual command and in there most probably in the code setting up the redirection (as you say it only fails with redirection).gdb. Usingset follow-fork-mode child. It will trace the first child, so you have to only set it just before running the command.args? Many questions, again the code above seems fine. Anstrace -fwould also be very insightful, @Vinoth.