Skip to content
Snippets Groups Projects
Commit fe89f0b7 authored by Andrew To's avatar Andrew To
Browse files

resubmitting question due to git commit problems in the last submission

parent 0fb74329
Branches
No related tags found
No related merge requests found
1. Can you think of why we use `fork/execvp` instead of just calling `execvp` directly? What value do you think the `fork` provides? 1. Can you think of why we use `fork/execvp` instead of just calling `execvp` directly? What value do you think the `fork` provides?
> **Answer**: _start here_ > **Answer**: If the execvp runs successfully, the process ends. Therefore, we need to use the fork create a child process so that when we have done with the current exe within the child process, we can move back to the "checkpoint" status so that the program will continue until "exit" command is read.
2. What happens if the fork() system call fails? How does your implementation handle this scenario? 2. What happens if the fork() system call fails? How does your implementation handle this scenario?
> **Answer**: _start here_ > **Answer**: If it fails, no child is created, so we shouldn't run the execvp. To handle this, I use a condition to check the return of fork(), and stops if fork fail. If it's 0, it will be successful and we can safely run the execvp().
3. How does execvp() find the command to execute? What system environment variable plays a role in this process? 3. How does execvp() find the command to execute? What system environment variable plays a role in this process?
> **Answer**: _start here_ > **Answer**: The execvp() find searches the PATH to the binaries to the new program and replace the current process by this program.
4. What is the purpose of calling wait() in the parent process after forking? What would happen if we didn’t call it? 4. What is the purpose of calling wait() in the parent process after forking? What would happen if we didn’t call it?
> **Answer**: _start here_ > **Answer**: The wait() is used for telling the parent process waits for the child to complete its current process. If we didn't call it, the parent may not know the exit status of the child process, which may cause potential issues.
5. In the referenced demo code we used WEXITSTATUS(). What information does this provide, and why is it important? 5. In the referenced demo code we used WEXITSTATUS(). What information does this provide, and why is it important?
> **Answer**: _start here_ > **Answer**: The WEXITSTATUS() is used for extracting the status code from the child process. It's important to pass the exit code of child process to its parent, so that we can control the exit code of the program.
6. Describe how your implementation of build_cmd_buff() handles quoted arguments. Why is this necessary? 6. Describe how your implementation of build_cmd_buff() handles quoted arguments. Why is this necessary?
> **Answer**: _start here_ > **Answer**: For quoted arguments, since there is always at least 1 space before a new argument, so I use strchr to get the first space. Then, if the pointer points to a double quotation mark, it will save the current position, then implement one by one until reach another double quotation mark, then use the new position and old position to extract the argument. After that, the loop continues with a new strchr() command and the same process. It's necessary if we don't care about the quoted arguments, we will inaccurately parse arguments, which may lead to many potential issues in many commands which have limited number of arguments (for example: cd)
7. What changes did you make to your parsing logic compared to the previous assignment? Were there any unexpected challenges in refactoring your old code? 7. What changes did you make to your parsing logic compared to the previous assignment? Were there any unexpected challenges in refactoring your old code?
> **Answer**: _start here_ > **Answer**: Comparing to the previous assignment, I don't use a list of command in this assignment and just use a buffer instead. Therefore, I can only store 1 command at a time. Moreover, I saved both command and arguments in an array. It was quite challenging when I have to deal with the quoted string since I have to combine the strchr() and the normal pointer implementation, which was so complex and made many unexpected bugs.
8. For this quesiton, you need to do some research on Linux signals. You can use [this google search](https://www.google.com/search?q=Linux+signals+overview+site%3Aman7.org+OR+site%3Alinux.die.net+OR+site%3Atldp.org&oq=Linux+signals+overview+site%3Aman7.org+OR+site%3Alinux.die.net+OR+site%3Atldp.org&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBBzc2MGowajeoAgCwAgA&sourceid=chrome&ie=UTF-8) to get started. 8. For this quesiton, you need to do some research on Linux signals. You can use [this google search](https://www.google.com/search?q=Linux+signals+overview+site%3Aman7.org+OR+site%3Alinux.die.net+OR+site%3Atldp.org&oq=Linux+signals+overview+site%3Aman7.org+OR+site%3Alinux.die.net+OR+site%3Atldp.org&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBBzc2MGowajeoAgCwAgA&sourceid=chrome&ie=UTF-8) to get started.
- What is the purpose of signals in a Linux system, and how do they differ from other forms of interprocess communication (IPC)? - What is the purpose of signals in a Linux system, and how do they differ from other forms of interprocess communication (IPC)?
> **Answer**: _start here_ > **Answer**: In general, signals notify the process that an event has occurred. Each signal has a current disposition, which determines how the process behaves when it is delivered the signal. Other forms of IPC are used to allow processes to communicate in different forms like sharing data, or message passing.
- Find and describe three commonly used signals (e.g., SIGKILL, SIGTERM, SIGINT). What are their typical use cases? - Find and describe three commonly used signals (e.g., SIGKILL, SIGTERM, SIGINT). What are their typical use cases?
> **Answer**: _start here_ > **Answer**:
- SIGKILL: Kill the process
- SIGTERM: Terminate the process
- SIGINT: Interrupt the process
They are usually used for terminating the process, but they have some difference. SIGKILL will kill the process immediately without saving any memory, while SIGTERM may be blocked or ignored. SIGINT is requested by user (like Cirl+C in Mac).
- What happens when a process receives SIGSTOP? Can it be caught or ignored like SIGINT? Why or why not? - What happens when a process receives SIGSTOP? Can it be caught or ignored like SIGINT? Why or why not?
> **Answer**: _start here_ > **Answer**: It will stop/pause the process, and it can't be caught or ignored. The SIGINT is designed to forcefully terminate the process when it's unresponsive.
\ No newline at end of file
...@@ -221,7 +221,7 @@ EOF ...@@ -221,7 +221,7 @@ EOF
# Strip all whitespace (spaces, tabs, newlines) from the output # Strip all whitespace (spaces, tabs, newlines) from the output
stripped_output=$(echo "$output" | tr -d '[:space:]') stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching # Expected output with all whitespace removed for easier matching
expected_output="Linuxtux25.15.0-121-generic#131-UbuntuSMPFriAug908:29:53UTC2024x86_64x86_64x86_64GNU/Linuxdsh2>dsh2>cmdloopreturned0" expected_output="Linuxtux45.15.0-133-generic#144-UbuntuSMPFriFeb720:47:38UTC2025x86_64x86_64x86_64GNU/Linuxdsh2>dsh2>cmdloopreturned0"
# These echo commands will help with debugging and will only print # These echo commands will help with debugging and will only print
#if the test fails #if the test fails
...@@ -245,7 +245,7 @@ EOF ...@@ -245,7 +245,7 @@ EOF
stripped_output=$(echo "$output" | tr -d '[:space:]') stripped_output=$(echo "$output" | tr -d '[:space:]')
# Expected output with all whitespace removed for easier matching # Expected output with all whitespace removed for easier matching
expected_output="batsdragon.cdshdsh_cli.cdsh.dSYMdshlib.cdshlib.hinput.txtmakefileshell_roadmap.mdstudent-testtestdsh2>dsh2>cmdloopreturned0" expected_output="batsdragon.cdshdsh_cli.cdsh.dSYMdshlib.cdshlib.hinput.txtmakefileshell_roadmap.mddsh2>dsh2>cmdloopreturned0"
# These echo commands will help with debugging and will only print # These echo commands will help with debugging and will only print
#if the test fails #if the test fails
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.ok</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment