SD 212 Spring 2026 / Homeworks


hw16: Shakes

  • Due before the beginning of class on Wednesday, March 18

Today’s homework asks you to run a small bash script that executes a provided Python program 10 times. You will then modify the script so that the 10 runs all happen concurrently and compare the results.

You will need to submit a Google form answering some specific questions about your experiments.

Downloads

Run git pull in your sd212 directory.

You should see a new folder with two files:

Tasks and questions

For this homework, we are mostly asking you to experiment with the code that you are given and make a couple small modifications to the bash script. You don’t need to write a lot of code; this is more about testing things for yourself and understanding what’s going on.

Complete the tasks below and fill in your answers by completing this Google Form before the deadline: https://forms.gle/xRtufNVe39tEJtvi8

  1. Look at the code in shakes.py. Maybe try running it on the command line by typing for example python3 shakes.py 15.

    Describe briefly what this program does.

  2. The bash script you downloaded run-shakes.sh just runs the Python program with ten different numbers. Time the execution by running on the command line:

    time bash run-shakes.sh

    You will see three timing numbers reported. The first (“real”) is the actual elapsed “real” time, and the second (“user”) is the amount of CPU time that was used. Answer this question by reporting these two numbers.

  3. Now modify run-shakes.sh so that it runs the Python programs concurrently by backgrounding them. You need to make two changes:

    1. Add a & at the end of each line so that the python3 programs run in the background, like this:

      python3 shakes.py 16 &
    2. Add a new line at the end with the single command wait

    After making these changes, time the execution again:

    time bash run-shakes.sh

    and report the real and user time numbers.

  4. Besides the timing, what is different about the output from the “parallel”/backgrounded version compared to the original version?