Description
Individual assignment. No group work allowed. Weight: 6% of the final grade.
Link to the assignment web page: https://sites.google.com/site/pfederlcpsc457winter2018/assignments/assignment-2
Q1 – Written question (4 marks)
A. Define “DMA”.
B. Define “multiprogramming”.
C. Would the concept of multiprogramming be practical on a computer that does not support DMA? Why or why not?
Q2 – Written question (3 marks)
A. Describe how a wrapped system call, e.g. read() in libc, invokes the actual system call in the kernel.
B. Is it essential that a wrapper of a system call is named the same as the underlying system call?
Q3 – Written question (4 marks)
A. Is it possible for a process to go from blocking state to running state?
B. What about going from ready state to blocking state?
For both parts: if you answer “yes”, describe an example, if you answer “no”, describe why not.
Q4 – Written question (3 marks)
What is a context switch? Describe the actions taken, including the information to be saved/restored, during a context switch?
Q5 – Programming question (10 marks)
Write a bash shell script “scan.sh” that takes two arguments:
1. suffix – a string
2. N – a positive integer
Your shell script will recursively scan the current directory for all files ending with the given suffix, then sort the files by their size, and then print the the filenames of the largest N files to the standard output, followed by the sum of their sizes. Each file reported should be followed by the size of the file in bytes. If the total number of files found is less then N, report all files. The listed files should be sorted by the size, in descending order.
Sample output:
$ scan.sh jpg 5
./face.jpg 88374
./a/tree.jpg 38883
./b/housejpg 3001
./a/b/jpg 233
Total size: 218830
Hints:
find, sort, head, awk
• You can assume there will be no spaces in any of the filenames or directory names.
Q6 – Programming question (15 marks)
Implement Q5 in C or C++, and name your program “scan.c” or “scan.cpp”. Your C/C++ program can make a one time use of the system() or popen() functions to invoke an external command to get the recursive list of files in the current directory. All other operations must be performed in C/C++, such as:
• determining the file size,
• filtering filenames based on the extension,
• sorting,
• calculating the sum.
• system() to find all files recursively in a directory, and save them to a text file, e.g. system(“find . –type f > temp.txt”);
• popen() to find all files recursively, and read the results directly, e.g.
FILE * fp = popen(“find . –type f”, “r”);
• stat() to determine the size of the file;
• qsort() for C or std::sort() for C++, for sorting purposes.
• the total number of files in the directory will be less than 1000, and • the maximum pathname length of any file will be less than 512.
The output of your C/C++ program should be identical to the output of your bash script from Q5.
Q7 – Written question (3 marks)
Run “strace -c” and “time” on your bash script from Q5 and your C/C++ program from Q6 and compare the results. Include the output of the above commands in your report, and explain why the results are different.
Q8 – Programming question (10 marks)
Your program will divide the array into T groups of roughly equal size:
• the first T-1 groups will contain ceil(N/T) number of elements; • the last group will contain the remaining elements.
$./sum input.txt 2
Thread 1: 19
Thread 2: 174
Sum = 193
The numbers after the word “Thread” in each line are the thread IDs. During the marking session your TAs will run your code on different input files and with different thread numbers, so it is important that your program accepts command-line arguments instead of hardcoded input file name and the number T.
Submission
You should submit 4 files for this assignment:
• Answers to the written questions combined into a single file, called either report.txt or report.pdf. Do not use any other file formats.
• Your solutions to Q5, Q6 and Q8 in a files called scan.sh, scan.c, sum.c.
Since D2L will be configured to accept only a single file, you will need to submit an archive, eg.
assignment2.tgz. To create such an archive, you could use a command similar to this:
tar czvf assignment2.tgz report.pdf scan.sh scan.c sum.c
General information about all assignments:
4. All assignments should include contact information, including full name, student ID and tutorial section, at the very top of each file submitted.
http://www.ucalgary.ca/pubs/calendar/current/k-5.html.
7. Only one file can be submitted per assignment. If you need to submit multiple files, you can put them into a single container. The container types supported will be ZIP and TAR. No other formats will be accepted.




Reviews
There are no reviews yet.