Skip to content
Snippets Groups Projects
Select Git revision
  • main default
1 result

questions.md

Blame
  • questions.md 2.59 KiB
    1. In this assignment I suggested you use fgets() to get user input in the main while loop. Why is fgets() a good choice for this application?

      Answer: fgets is really fast, and it also reads tbe input stream safetly, and can handle inputs better.

    2. You needed to use malloc() to allocte memory for cmd_buff in dsh_cli.c. Can you explain why you needed to do that, instead of allocating a fixed-size array?

      Answer: The buffers fixed buffers are worse, because they can be wasteful, or even too small. So it can't handle a varied input pull as well as a dynamically allocated array.

    3. In dshlib.c, the function build_cmd_list()` must trim leading and trailing spaces from each command before storing it. Why is this necessary? If we didn't trim spaces, what kind of issues might arise when executing commands in our shell?

      Answer: Reading strings could get messed up, because the space counts as a line so it could waste the char limits, and also make print statements hard to weird, and comparisons really hard.

    4. For this question you need to do some research on STDIN, STDOUT, and STDERR in Linux. We've learned this week that shells are "robust brokers of input and output". Google "linux shell stdin stdout stderr explained" to get started.

    • One topic you should have found information on is "redirection". Please provide at least 3 redirection examples that we should implement in our custom shell, and explain what challenges we might have implementing them.

      Answer: > overwrite redirection You would need to open a file and then put it into the command so there could be challenges.

      Append. Adding new data to a old file seems challenging. & making sure the input is merged correctly would be hard

    • You should have also learned about "pipes". Redirection and piping both involve controlling input and output in the shell, but they serve different purposes. Explain the key differences between redirection and piping.

      Answer: Piping puts one output into another, and redirection changes where the input goes.

    • STDERR is often used for error messages, while STDOUT is for regular output. Why is it important to keep these separate in a shell?

      Answer: seperating them, makes the errors stand out and makes it more readable.

    • How should our custom shell handle errors from commands that fail? Consider cases where a command outputs both STDOUT and STDERR. Should we provide a way to merge them, and if so, how?

      Answer: Our command should display messages that are clear and helpful, and to merge it would be >& i think.