Operating Systems 2026F: Assignment 4: Difference between revisions
| Line 15: | Line 15: | ||
==Questions== | ==Questions== | ||
# [3] | # [3] Can hard links be used to make files available in 3000contain2.sh's container? What about symbolic links? Is this the same as with [[Operating_Systems_2026F:_Tutorial_8#3000contain.sh|3000contain.sh]]'s container? Demonstrate with a simple experiment. Explain. | ||
# [3] | # [3] Change 3000contain2.sh so that it uses busybox's internal shell rather than bash. How can this change allow 3000contain2.sh to be simplified yet still work? What key functionality has been lost by this simplification? | ||
# [2] Create a small test program <tt>compare-pids.c</tt> that compares the PID produced from getpid() and the value returned by /dev/newgetpid from [[Operating_Systems_2026F:_Tutorial_7#newgetpid_module|Tutorial 7]]. It should take no command line inputs and should output "getpid: ??, newgetpid: ??" where the ?? are the PID values gotten from the two sources. Your answer should be the source code of your new program. | # [2] Create a small test program <tt>compare-pids.c</tt> that compares the PID produced from getpid() and the value returned by /dev/newgetpid from [[Operating_Systems_2026F:_Tutorial_7#newgetpid_module|Tutorial 7]]. It should take no command line inputs and should output "getpid: ??, newgetpid: ??" where the ?? are the PID values gotten from the two sources. Your answer should be the source code of your new program. | ||
# [2] How can you install the compare-pids binary into 3000contain2.sh's container so it is there when it first runs? How can you install it after the container is already running? | # [2] How can you install the compare-pids binary into 3000contain2.sh's container so it is there when it first runs? How can you install it after the container is already running? | ||
Latest revision as of 16:02, 24 November 2026
This assignment is not yet finalized.
Please submit the answers to the following questions via Brightspace by December 7, 2026. There are 20 points in 8 questions.
Submit your answers as a plain text file following this template. Name your answer file "comp3000-a4-<username>.txt" (where username is your MyCarletonOne username). Please make sure to use your correct student ID number otherwise your grades may not be properly recorded.
Your answers will be parsed by a script in order to help with grading so please preserve the format of the template. No other formats will be accepted.
Note that the file should be a UNIX text file, not a Windows text file (so LF line endings). See the Wikipedia page on text files to learn more. Most modern text editors can convert between different types of text files. Alternately, install the program dos2unix on the VM to convert.
You may use this validator page to make sure your answer file is properly named and formatted.
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.
Questions
- [3] Can hard links be used to make files available in 3000contain2.sh's container? What about symbolic links? Is this the same as with 3000contain.sh's container? Demonstrate with a simple experiment. Explain.
- [3] Change 3000contain2.sh so that it uses busybox's internal shell rather than bash. How can this change allow 3000contain2.sh to be simplified yet still work? What key functionality has been lost by this simplification?
- [2] Create a small test program compare-pids.c that compares the PID produced from getpid() and the value returned by /dev/newgetpid from Tutorial 7. It should take no command line inputs and should output "getpid: ??, newgetpid: ??" where the ?? are the PID values gotten from the two sources. Your answer should be the source code of your new program.
- [2] How can you install the compare-pids binary into 3000contain2.sh's container so it is there when it first runs? How can you install it after the container is already running?
- [2] How does the behavior of compare-pids change when run inside of the 3000contain2.sh produced container?
- [2] Change line 47 of newgetpid.c so that it calls task_tgid_nr() instead. How does this change impact the behaivor of compare-pids? Why?
- [3] Modify newgetpid.c so it outputs both the ouput of task_tgid_nr() and task_tgid_vnr(). Make sure the output labels them with what they actually are (rather than the name of the functions that produced the values).
- [3] Does the root user inside 3000contain2.sh's container have the same privileges as the root user outside of the container? How can you verify that these privileges are the same or are different? Present a test that verifies your conclusion.
Code
3000contain2.sh
#!/bin/bash
#
# 3000contain2.sh
#
MP='3000fs2'
IMAGE='3000fsimage2'
BLOCKS=60000
SETUP='3000setupfs2.sh'
if [ $UID != 0 ]; then
echo "Please run this script as root."
exit
fi
mkdir $MP
cd $MP
mkdir bin sbin usr usr/bin usr/sbin etc proc sys dev root home lib \
usr/lib lib64 tmp var var/tmp var/lib run usr/share usr/share/terminfo
cp /usr/bin/busybox usr/bin
cp /bin/bash bin
cp /lib64/ld-linux-x86-64.so.2 lib64
cp /sbin/ldconfig* sbin
cp -a /etc/ld.so.conf* etc
cp `ldd /bin/bash | awk '{print $3}'` lib
chmod 1777 tmp var/tmp
cp -a /etc/passwd /etc/shadow /etc/group /etc/gshadow etc
TERMDIR=${TERM:0:1}
mkdir usr/share/terminfo/$TERMDIR
cp /usr/share/terminfo/$TERMDIR/$TERM usr/share/terminfo/$TERMDIR/$TERM
echo '#!/usr/bin/busybox sh' > $SETUP
echo '/usr/bin/busybox --install' >> $SETUP
echo '/sbin/ldconfig' >> $SETUP
echo 'mount -t devtmpfs udev /dev' >> $SETUP
chmod 0755 $SETUP
chroot . /$SETUP
rm $SETUP
unshare --root=. -f -p --mount-proc