Don’t forget to include what outside resources you used to complete each of your answers, including other students, man pages, and web resources. You do not need to list help from the instructor, TA, or information found in the textbook.
First, download and run countdown.sh. You can make it executable after downloading by running “chmod a+x countdown.sh”. After this, it should run like any other executable.
Next, download and compile 3000capture.c as usual. Try the following to get an idea of how 3000capture and countdown.sh work:
./countdown.sh
./3000capture /bin/ls /dev/null -la
cat 3000capture.log
cat > bc-input.txt
4+5
7*2
1-6
^D # type ctrl-D to end the file
./3000capture /usr/bin/bc bc-input.txt -l
cat 3000capture.log
./3000capture ./countdown.sh /dev/null
cat 3000capture.log
Questions
[2] If we read from /dev/null, what data do we get? How can you verify this?
[2] 3000capture requires commands to be fully qualified pathnames. How can you modify 3000capture so that if a command doesn’t start with a /, 3000capture searches the current PATH to find the right program? If PATH isn’t defined it should search a default set of directories.
[2] What is the purpose of the fflush() call in parent() at line 36? Why isn’t it needed elsewhere in parent()?
[2] How could you fix 3000capture so it sends its output to the file specified by the CAPTURE environment variable? If there is no CAPTURE environment variable, it should use the same default as it does currently.
[2] How many processes does countdown.sh create, and how many executables does it run? How can you verify this using bpftrace?
[2] What is child_exited used for? Why is it needed?
[2] How can you create a shell script that sends a SIGTERM signal to whatever process that ran it (its parent)? What happens when you run 3000capture on it?
[2] How can you verify that the shell script from the previous question is actually sending the right signal using bpftrace?
[4] How could you change 3000capture so that when it receives a SIGUSR1 signal it
Prints “SIGUSR1 received, shutting down.”
Sends a SIGTERM signal to its child
Waits at least one second
If the child has terminated, it reports how the child has terminated, whether from a signal or whether it returned normally.
If the child has not terminated, it reports “Child still running, aborting.” and exits with a return value of -10.