Fall 2015 - CMPSC311 - Systems Programming
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Fall 2015 - CMPSC311 - Systems Programming
Professor McDaniel — Wednesday, November 4th, 2015
Please read the instructions and questions carefully. You will be graded for clarity and correctness. You have 50 minutes to complete this exam, so focus on those questions whose subject matter you know well. This is a closed book and note exam. Write legibly and carefully check your answers before handing in the completed exam.
Short Answer - some will be one or two words – no more than 1 sentence. (40/100 points)
1. (5pts) What C-library function does a lexicographic comparison of character arrays?
2. (5pts) What is the acronym for the default character encoding scheme in UNIX?
3. (5pts) Name two C-library functions for dynamically allocating memory from automatically managed data regions?
4. (5pts) Why are the file permissions in a UNIX system called discretionary access control?
5. (5pts) Memory leaks occur when you fail to call what function?
6. (5pts) What is the purpose of the page table?
7. (5pts) What is the size of the memory region allocated for the follwing declaration? char *mystring = "hello"
8. (5pts) What is the name of the shell we learned about writing scripts for in class lecture?
Long Answer - no more than 4 sentences (20/100 points)
9. (10pts) What is the central advantage of using memory mapping over program breaks?
10. (10pts) What is the difference between a watchpoint and a breakpoint?
Programming/Word Problems - take your time and answer clearly and completely. (40/100 points)
11. (10pts) In one sentence, explain what each of these signals means.
(a) SIGTERM
(b) SIGKILL
(c) SIGHUP
(d) SIGSEGV
(e) SIGUSR1
12. (10pts) Write the following code:
(a) Define a pointer to a float value fval and a float temp.
(b) Dynamically allocate an array of 24 float values and assign the pointer to fval.
(c) Create a loop that assigns each value its index plus 0.5. You can assume you have a integer i to use to iterate.
(d) Swap the 7th and 8th value using temp a temporary holder varaible.
(e) In a single C code statement, copy the first 5 elements to the last 5 see above
13. (10pts) You have a 4-element fully associative cache that can hold one addressable unit per cache line and an LRU policy. The addressable units have address 0-6, and time is measured using an integer step clock. The cache will be asked to process the following workload from the initial cache state shown below (SHOW YOUR WORK - not doing so will result in a zero for this question). Answer the following questions.
Workload:
address 5 at time 11
address 6 at time 12
address 4 at time 13
address 6 at time 14
address 0 at time 15
address 3 at time 16
address 1 at time 17
address 2 at time 18
address 2 at time 19
Initial cache state:
0 |
1 |
2 |
3 |
Line |
1 |
3 |
2 |
5 |
Address |
8 |
9 |
10 |
3 |
Last used |
(a) What is the state of the cache after the workload completes?
0 |
1 |
2 |
3 |
Line |
|
|
|
|
Address |
|
|
|
|
Last used |
(b) What is the hit ratio for the workload?
(c) What is the average memory access time for the workload if a cache access cost 200 usec and a miss cost penalty 5000 usec?
int pointgame(void) {
int idx;
char vals[] = {0, 1, 2, 3}, *ptr1, *ptr2, *ptr3, *ptr4;
ptr1 = &vals[0];
ptr2 = &vals[1];
ptr3 = &vals[2];
ptr4 = &vals[3];
ptr1 = &vals[(int)*ptr2];
ptr2 += *ptr1;
idx = (((*ptr4)- (*ptr1))+(*ptr3))%4;
ptr3 += vals[idx];
ptr4 = &vals[11/8];
printf( "Pointer printf( "Pointer printf( "Pointer printf( "Pointer return(0);
}
1 = %d\n", (int)*ptr1 );
2 = %d\n", (int)*ptr2 );
3 = %d\n", (int)*ptr3 );
4 = %d\n", (int)*ptr4 );
14. (10pts) Consider the code above. Compute the four printed values above and complete the output below:).
(a) Pointer 1 =
(b) Pointer 2 =
(c) Pointer 3 =
(d) Pointer 4 =
2023-03-30