CENG 341 FALL 2014 Due date: 27 October 2014 23:50 HOMEWORK 1 Part 1: Programming Question 1(10points): Write a program that calls fork(). Before calling fork(), have the main process access a variable (e.g., x) and set its value to something (e.g., 100). What value is the variable in the child process? What happens to the variable when both the child and parent change the value of x? Question 2(15points): Write another program using fork(). The child process should print “hello”; the parent process should print “goodbye”. a) You should try to ensure that the child process always prints first; can you do this without calling wait() in the parent? b) Now write a program that uses wait() to wait for the child process to finish in the parent. What does wait() return? What happens if you use wait() in the child? Question 3(15points): Write a program that generates simultaneous processes to execute the following 4 commands at the same time. You may use UNIX Process API functions fork, wait and execvp. The relationships among the processes are up to you. Just make sure you use the minimum number of processes to execute the programs simultaneously. Commands: ls –l pwd mkdir <inputdir_name> rm –r <anydir_name> Part 2: Scheduling Algorithms: SJF, FIFO, RR In this part of the assignment, you will use a special python program to generate scheduling simulations: scheduler.py. This program will be provided as attachment to this homework. With this program you will be able to generate your own scheduling scenarios and actually see the computed turnaround time, response time and wait time results. With special option flags you will be able to set parameters such as the scheduling algorithm, the number of jobs, random seeds to generate job running times (lengths). For a full list of options, use the –h flag. How to run the scripts: To be able to run these scripts, you will need to have python installed on your system. For Windows users, in Cygwin search for python and install everything in the search results. There are two options to run your program: ./scheduler.py –p FIFO –j 3 –s 100 or python ./scheduler.py –p FIFO –j 3 –s 100 Here –p FIFO represents the algorithm, -j represents the number of jobs and –s represent a random see to randomly generate job lengths. Instead of using a random seed you could give the running times yourself with the –l option: ./scheduler.py -p SJF -l 5,10,15 First run your simulation and calculate the scheduling results for turnaround time and response time, then use the –c flag to actually see the results. $ ./scheduler.py -p FIFO -j 3 -s 100 -c ARG policy FIFO ARG jobs 3 ARG maxlen 10 ARG seed 100 Here is Job 0 Job 1 Job 2 the job list, with the run time of each job: ( length = 2 ) ( length = 5 ) ( length = 8 ) ** Solutions ** Execution trace: [ time 0 ] Run job 0 for 2.00 secs ( DONE at 2.00 ) [ time 2 ] Run job 1 for 5.00 secs ( DONE at 7.00 ) [ time 7 ] Run job 2 for 8.00 secs ( DONE at 15.00 ) Final statistics: Job 0 -- Response: 0.00 Job 1 -- Response: 2.00 Job 2 -- Response: 7.00 Average -- Response: 3.00 Turnaround 2.00 Wait 0.00 Turnaround 7.00 Wait 2.00 Turnaround 15.00 Wait 7.00 Turnaround 8.00 Wait 3.00 Question 4(15points): For what types of workloads does SJF deliver the same turnaround times as FIFO. Give an example. For what types of workloads and quantum lengths does SJF deliver the same response times as RR? Give an example. Question 5(15points): What happens to response time with SJF as job lengths increase? Use a graphic to represent the trend. Part 3. MLFQ Algorithm In this part of the assignment, you will use a Python simulator called scheduler-mlfq.py The usage options of the MLFQ scheduler is given below. Usage: scheduler-mlfq.py [options] Options: -h, --help show this help message and exit -s SEED, --seed=SEED the random seed -n NUMQUEUES, --numQueues=NUMQUEUES number of queues in MLFQ (if not using -Q) -q QUANTUM, --quantum=QUANTUM length of time slice (if not using -Q) -Q QUANTUMLIST, --quantumList=QUANTUMLIST length of time slice per queue level, specified as x,y,z,... where x is the quantum length for the highest-priority queue, y the next highest, and so forth -j NUMJOBS, --numJobs=NUMJOBS number of jobs in the system -m MAXLEN, --maxlen=MAXLEN max run-time of a job (if random) -M MAXIO, --maxio=MAXIO max I/O frequency of a job (if random) -B BOOST, --boost=BOOST how often to boost the priority of all jobs back to high priority (0 means never) -i IOTIME, --iotime=IOTIME how long an I/O should last (fixed constant) -S, --stay reset and stay at same priority level when issuing I/O -l JLIST, --jlist=JLIST a comma-separated list of jobs to run,in the form x1,y1,z1:x2,y2,z2:... where x is start time, y is run time, and z is how often the job issues an I/O request -c compute answers for me Question 6(15points) Craft a workload with two jobs and scheduler parameters so that one job takes advantage of the older Rules 4a and 4b (turned on with the -S flag) to game the scheduler and obtain 99% of the CPU over a particular time interval. Question 7(15points) Given a system with a quantum length of 10 ms in its highest queue, how often would you have to boost jobs back to the highest priority level (with the -B flag) in order to guarantee that a single long-running (and potentially-starving) job gets at least 5% of the CPU? Give an example execution trace.