Marquette University logo      

Midterm Examination 1

 

COEN 183, Tuesday, February 13

Link to COSC 125 exam, Wednesday, February 14.

Directions:

Read and follow the directions.

  • Write on five of the six questions. Each problem is worth 20 points.
  • Read the entire exam. If there is anything you do not understand about a question, please ask at once.
  • If you find a question ambiguous, begin your answer by stating clearly what interpretation of the question you intend to answer.
  • Begin your answer to each question at the top of a fresh sheet of paper. [Or -5]
  • Write only on one side of a sheet.
  • Be sure your name is on each sheet of paper you hand in. [Or -5]
Material in shaded boxes are intended as hints at what a good solution might be. They are not intended to be complete solutions

Grade distribution:

 

 

Problem 1 Process vs. Thread

Selected by 18 of 19 students. Average score: 15.8 of 20.

Compare and contrast a process and a thread.

Hint: "Compare and contrast" is a design pattern for examinations. In general, your answer to a "compare and contrast A and B" question should follow the pattern:

  1. Define A
  2. Define B
  3. Describe ways in which A and B are similar
  4. Describe ways in which A and B are different
  5. Summary/conclusion

A process is a program in execution [p. 82]. A process consists of a Process Control Block (see problem 2).

A thread is more difficult to define. The book does not give a tight definition. A thread is a single line of execution. Threads are subunits of processes. A thread consists of a thread control block (See COSC exam problem 3).

Process and threads both are units of execution. They may be scheduled similarly.

Processes and threads differ mainly in their overhead, especially memory requirements and CPU time to manipulate, for creation, context switching, and deletion. See problem 4. Processes have separate copies of code, data, and other attributes. Threads belonging to the same process share code and as much other memory as possible. Multiple threads may belong to one process

Problem 2 Process Control Block

Selected by 14 of 19 students. Average score: 19.0 of 20.

List attributes of a process. For each, give a name suggestive of its purpose, a likely data type, and a description. When appropriate, tell what values the attribute might assume. For example

 

Name Type Description
ID integer Process identifier
     

 

Hint: Pseudo-English is fine. I am not looking for near-C code.

See Section 3.1.3 or class notes for Chapter 3 PCB

Need to store Registers when switched out - Could be stored in stack space

Need to know process state - Could be deduced from which queue it is in

Problem 3 Read C Code

Selected by 17 of 19 students. Average score: 10.9 of 20.
This relatively low score suggests you might see another treacherous C program on another exam.

Consider this C program:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int value;
FILE *LOGFILE;

void *runner(void *param) {
    int a = 19;
    value = 3;

    printf("Line A: Value = %d; a = %d\n", value, a);
    fprintf(LOGFILE, "Line A: Value = %d; a = %d\n", value, a);
    value = value + value;
    printf("Line B: Value = %d; a = %d\n", value, a);
    fprintf(LOGFILE, "Line B: Value = %d; a = %d\n", value, a);

	pthread_exit(0);
}


int main(void) {
    int a = 17;
    value = 5;
    pthread_t tid;
    pthread_attr_t attr;
    
    LOGFILE = fopen("prob3_4.log", "w");  /* Open file for write */
    fprintf(LOGFILE, "Problem 3.4 log:\n\n");  /* Write to file  */
    
    pthread_attr_init(&attr);
    pthread_create(&tid, &attr, runner, NULL);   /* Creates and STARTS thread */
 
    printf("Line C: Value = %d; a = %d\n", value, a);
    fprintf(LOGFILE, "Line C: Value = %d; a = %d\n", value, a);
    pthread_join(tid, NULL);                     /* Waits for thread to finish */
    printf("Line D: Value = %d; a = %d\n", value, a);
    fprintf(LOGFILE, "Line D: Value = %d; a = %d\n", value, a);

    fclose(LOGFILE);  /* Close file */
    exit(0);
}
  1. What is printed on the screen?
  2. Explain your answer to a)
  3. What is in the log file?
  4. Explain your answer to part c)

Hint: The purpose of this question is to examine your understanding. I guarantee that I have run this code, but it may not illustrate the best coding practices. Do not let me trick you.

See Problem 3.4, p. 117. The issues you must address are:

  • What is shared?
  • What is not shared?
  • In what order do events happen?

Note well: I warned you this is a trick question. The fundamentally correct answer is, "I don't know exactly, but here is what I do know ..."

  1. Line A (3, 19) prints before Line B (6, 19)
    Line C (5, 17) prints before Line D (6, 17)
    Line D prints after runner completes
    You can make no assumptions about which thread runs first.
    You can make no assumptions about when each thread may be interrupted.
  2. int a is local to each thread
    value is shared, so change in runner is reflected in main
  3. Probably same as screen
  4. You can make no assumptions about when each thread may be interrupted.
    Threads SHARE global variables, which include file control block information.

When I ran this program on my Mac, here is what I happened to get. It represents a correct answer, but I do NOT consider this the correct answer.

Output:

make asThread
gcc -o prob3_4asThread prob3_4asThread.c
./prob3_4asThread 7
Line C: Value = 5; a = 17
Line A: Value = 3; a = 19
Line B: Value = 6; a = 19
Line D: Value = 6; a = 17
     

prob3_4.log:

Problem 3.4 log:
 
Line C: Value = 5; a = 17
Line A: Value = 3; a = 19
Line B: Value = 6; a = 19
Line D: Value = 6; a = 17

Problem 4 Context Switch

Selected by 18 of 19 students. Average score: 14.7 of 20.

In the context of scheduling and dispatching of processes,

  1. What is the purpose of a context switch?
  2. Describe the steps, in order, taken by a kernel to context-switch between processes

See Problem 3.2, p. 116. This question tests whether you know what you must do in Homework 4

Context switch changes which process holds the CPU. It does not interrupt a running process, nor does it do the work of the scheduler to determine which is the next process to run.

From Dr. Brylow's lecture:

 

 

How is control handed over to the incoming process?

Think for a moment. Can you write code to save or to restore the Program Counter? No. Why not? In our design, the last instruction executed by the context switch is RETURN, as if from a function call.

Problem 5 System Boot

Selected by 19 of 19 students. Average score: 13.3 of 20.

What happens when you turn your computer on? List the steps that the operating system must perform on typical personal computer from the instant the power is switched on until the system is ready and waiting for your normal use. Suggest where code/information needed is stored.

See p. 71. You might distinguish:

  1. Hardwired load of Program Counter pointing to a predefined memory location. There has to be something in the Program Counter for the first instruction to execute. Role of PC is critical
  2. Execute initial bootstrap program, probably from ROM
  3. Bootstrap may run diagnostics
  4. Initialize hardware registers, memory, device controllers, etc. I need a disk driver loaded before I can load the next step from the disk.
  5. Load single block from disk boot block
  6. That loader knows where on disk to find rest of bootstrap loader & length
  7. Load rest of OS bootstrap loader
  8. OS bootstrap loader loads OS kernel into memory
  9. Transfer control to OS kernel
  10. OS kernel performs initializations
  11. Spawns OS processes
  12. Finally, await user input

Problem 6 Scheduling

Selected by 9 of 19 students. Average score: 13.8 of 20.

Choose one of

  • Solaris
  • Windows XP
  • Linux

Describe its scheduling policies.

See Section 5.6, p. 173 ff.

 

 
  Marquette University. Be The Difference. Marquette | Corliss |