diff --git a/3-ShellP1/questions.md b/3-ShellP1/questions.md new file mode 100644 index 0000000000000000000000000000000000000000..c3a0196b8117532d22f6ea0fd4cb720e0c91370d --- /dev/null +++ b/3-ShellP1/questions.md @@ -0,0 +1,38 @@ +# Assignment Questions + +## 1. fgets() for User Input +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? + +'fgets()' is good for this assignment, rather than getline(), because it only allocates enough memory up to the size given as a argument, meaning it's much safer than just grabbing random bits of memory and sprting through them. + +## 2. Memory Allocation with malloc() +You needed to use `malloc()` to allocate memory for `cmd_buff` in `dsh_cli.c`. Can you explain why you needed to do that instead of allocating a fixed-size array? + +You need to use 'malloc' because you are dynamically allocating memory and it allows you to not waste space when allocating memory for 'cmd_buff'. + +## 3. Trimming Spaces in build_cmd_list() +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? + +The main issue that arises is that even if logically your code would split the buffer into executable and arguments, in practice it actually doesn't because it treats each arguement as an additional executable. + +## 4. STDIN, STDOUT, and STDERR in Linux +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. + +### Redirection +One topic you should have found information on is **redirection**. Please provide at least **three** redirection examples that we should implement in our custom shell and explain what challenges we might have in implementing them. + +(1) output redirection -- redirecting **STDOUT** to a file +(2) input redirection -- redirecting **STDIN** from a file +(3) error redirection -- redirecting **STDERR** to an error file + +I think the main challengs that will come with implementing each of the the redirection methods will be properly rewriting over files or take the content of files and pushing it towards **STDIN**, which is something we haven't done much if at all. + +### Piping +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.** + +Redirection changes the direction of the input or output for a single command, whereas piping feeds the output of one command into the input of another command. Additiobally, redirection is used with taking the input/output of **STDIN, STDOUT, and/or STDERR** and any file being used in the redirection, whereas piping only utilizes commands. + +### Error Handling +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? + +Generlly when a command fails, it exits with a specific message redirected to **STDERR** and with a specific exit code that lets you know relatively what the issue was with the command. If a commaand deals with both **STDOUT** and **STDERR**, **STDOUT** should only be used for the normal ouput of the command and **STDERR** should be used for exceptions where the command wouldn't function properly or at all.