Last update: 1/29/2017 -
Exercise #1. (solution)
Submission: you are turn submit your program file (a single
"C" or Python please) to handin by the due date.
This exercise has two objectives:
1. Install VirtualBox and the Ubuntu VM we will use for the class
2. Have you write a program and run it on your VM (and monitor it!!)
Step 1. Installing our VM.
Refer to the instructions at SetupVMs
Step 2. Simple exercise using Ubuntu.
- Write a very simple C program that falls into an infinite
loop. You can use something like this : ex1.c
- Open a shell on your VM and run your program.
- Open a second shell. Learn about the 'top' command
(issue a 'man top'). Find the process id of
the C program.
- Kill the C program from the second shell window. Use
the 'kill' command. Issue a 'man kill' to learn how
to do this.
There is nothing to handin - this is just to introduce you to VMs.
Solution: Follow these steps.You should open three terminal sessions on your VM. We will refer to each as term1, term2 and term3
- On your VM in term1, issue wget https://people.cs.clemson.edu/~jmarty/courses/Spring-2017/CPSC424/exercises/ex1.tar.gz
- unpack and build in a work directory...two programs are created - ex1A and ex1B.
- gzip -d ex1.tar.gz; tar -xf ex1.tar
- make clean; make
- In term2, do a 'man top' and get familiar with this tool (you should also learn about vmstat), then issue 'top'
- In term1, run the first program...this just loops forever : ./ex1A
- In term2 you should see the ex1A process consumes about 99% of the CPU. Note its pid (we will call it ex1PID).
- In term3, issue a 'man kill' and learn about the kill program. Issue 'kill ex1PID' which issues by default a SIGTERM. Run ex1A and try issueing other signals and see what happens.
Try the following:...(picks up from above, you need a 4th term session)
- In term1, run ex1A ...this just loops forever : ./ex1A, and monitor system in term2 with top.
- In term3, run a second instance of ex1A.
- In term4, issue man to learn about nice and renice. Assume the second instance of ex1A process ID is Instance2PID, issue 'sudo renice -5 -p Instance2PID'.
- In top, you should see the second instance's NI value go from 0 to -5, dropping the effective process priority from 20 to 15. Depending on your system, you might see the %CPU stay about the same (about 49% and 49% split) or you might see the instance with the higher PR use more than 50% of the CPU.When we talk about the scheduler, this will make more sense.