1

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)

15
  • 3
    Exit code 0x008b (139: Segmentatation violation) usually means it was terminated by a SIGSEGV, you have a segmentation fault somewhere, gdb should be able to tell you more. Commented Nov 26, 2012 at 10:41
  • gdb doesn't detect it as segmentation fault. Behaves the same. Commented Nov 26, 2012 at 10:45
  • 1
    I would add that since wc itself is unlikely to segfault even if you gave it invalid file descriptor, the segfault is probably between the fork call and the exec of the actual command and in there most probably in the code setting up the redirection (as you say it only fails with redirection). Commented Nov 26, 2012 at 10:47
  • 2
    You have to set up tracing into the child process in gdb. Using set follow-fork-mode child. It will trace the first child, so you have to only set it just before running the command. Commented Nov 26, 2012 at 10:50
  • 1
    Where's the backtrace? It's really hard to "imagine" it all correctly based off what you provided; need more information to avoid guessing. What is args? Many questions, again the code above seems fine. An strace -f would also be very insightful, @Vinoth. Commented Nov 26, 2012 at 11:38

1 Answer 1

0

The pointer which was passed in the execvp was NULL and hence got SIGSEGV.

The backend processing of the entered command to segregate them based on pipes and redirection had error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.