Quiz 1 - Operating Systems - Assignment | CSE 430, Quizzes of Operating Systems

Material Type: Quiz; Professor: Syrotiuk; Class: Operating Systems; Subject: Computer Science and Engineering; University: Arizona State University - Tempe; Term: Fall 2012;

Typology: Quizzes

2011/2012

Uploaded on 09/29/2012

hnquy
hnquy 🇺🇸

5

(2)

14 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ARIZONA STATE UNIVERSITY
CSE 430 Operating Systems Fall 2012
SLN 71250
Instructor: Dr. Violet R. Syrotiuk
Assignment #1
Available Tuesday 08/28/2012; due Tuesday 09/11/2012
This assignment covers Chapter 3 “Process Description and Control,” Chapter 4 “Threads,” and part of
Chapter 5 “Concurrency: Mutual Exclusion and Synchronization.”
1. Assume that at time 5 no system resources are being used except for the processor and memory. Now
consider the events below:
At time 5: P1executes a command to read from disk unit 3.
At time 15: P5’s time slice expires.
At time 18: P7executes a command to write to disk unit 3.
At time 20: P3executes a command to read from disk unit 2.
At time 24: P5executes a command to write to disk unit 3.
At time 28: P5is swapped out.
At time 33: An interrupt occurs from disk unit 2: P3’s read is complete.
At time 36: An interrupt occurs from disk unit 3: P1’s read is complete.
At time 38: P8terminates.
At time 40: An interrupt occurs from disk unit 3: P5’s write is complete.
At time 44: P5is swapped back in.
At time 48: An interrupt occurs from disk unit 3: P7’s write is complete.
For each time 19, 34, and 49, identify which state each process is in. If a process is blocked, further
identify the event on which is it blocked. Assume the process state transition diagram with two suspend
states. State any other assumptions that you need to make. [10 marks]
2. For an OS of your choice, old or new (e.g., your own computer, a smart phone):
(a) Find the equivalent of the process state transition diagram and process control block (PCB) and
discuss how they compare to the seven-state process state transition diagram (Figure 3.9) and
PCB (Table 3.5). Give sources for your information. [15 marks]
(b) If your OS is multi-threaded, which elements of the PCB should belong to a thread control block
and which should belong to a PCB? [5 marks]
3. Describ e the actions taken by a kernel to switch context between processes in a non-process kernel,
i.e., the kernel of the OS executes outside of any process. [5 marks]
4. Many current language specifications, such as for C and C++, are inadequate for multi-threaded
programs. This can have an impact on compilers and the correctness of code. Consider the following
declarations and function definition:
int global_positives = 0;
typedef struct list{
struct list *next;
double value;
}* list;
1
pf2

Partial preview of the text

Download Quiz 1 - Operating Systems - Assignment | CSE 430 and more Quizzes Operating Systems in PDF only on Docsity!

ARIZONA STATE UNIVERSITY

CSE 430 — Operating Systems — Fall 2012

SLN 71250

Instructor: Dr. Violet R. Syrotiuk

Assignment

Available Tuesday 08/28/2012; due Tuesday 09/11/

This assignment covers Chapter 3 “Process Description and Control,” Chapter 4 “Threads,” and part of Chapter 5 “Concurrency: Mutual Exclusion and Synchronization.”

  1. Assume that at time 5 no system resources are being used except for the processor and memory. Now consider the events below: At time 5: P 1 executes a command to read from disk unit 3. At time 15: P 5 ’s time slice expires. At time 18: P 7 executes a command to write to disk unit 3. At time 20: P 3 executes a command to read from disk unit 2. At time 24: P 5 executes a command to write to disk unit 3. At time 28: P 5 is swapped out. At time 33: An interrupt occurs from disk unit 2: P 3 ’s read is complete. At time 36: An interrupt occurs from disk unit 3: P 1 ’s read is complete. At time 38: P 8 terminates. At time 40: An interrupt occurs from disk unit 3: P 5 ’s write is complete. At time 44: P 5 is swapped back in. At time 48: An interrupt occurs from disk unit 3: P 7 ’s write is complete. For each time 19, 34, and 49, identify which state each process is in. If a process is blocked, further identify the event on which is it blocked. Assume the process state transition diagram with two suspend states. State any other assumptions that you need to make. [10 marks]
  2. For an OS of your choice, old or new (e.g., your own computer, a smart phone):

(a) Find the equivalent of the process state transition diagram and process control block (PCB) and discuss how they compare to the seven-state process state transition diagram (Figure 3.9) and PCB (Table 3.5). Give sources for your information. [15 marks] (b) If your OS is multi-threaded, which elements of the PCB should belong to a thread control block and which should belong to a PCB? [5 marks]

  1. Describe the actions taken by a kernel to switch context between processes in a non-process kernel, i.e., the kernel of the OS executes outside of any process. [5 marks]
  2. Many current language specifications, such as for C and C++, are inadequate for multi-threaded programs. This can have an impact on compilers and the correctness of code. Consider the following declarations and function definition:

int global_positives = 0;

typedef struct list{ struct list next; double value; } list;

void count_positives( list ell ){ list p; for( p = ell; p; p = p->next ) if( p->value > 0.0 ) ++global_positives; }

Consider the case in which thread A performs count positives on a list containing only negative values while thread B performs ++global positives;.

(a) What does the function do? (b) The C language only addresses single-threaded execution. Does the use of two concurrent threads create any problems or potential problems? (c) Some optimizing compilers (including gcc, which tends to be relatively conservative) will “opti- mize” count positives to something similar to: void count_positives( list ell ){ list p; register int r; r = global_positives; for( p = ell; p; p = p->next ) if( p->value > 0.0 ) ++r; global_positives = r; } What problem or potential problem occurs with this compiled version of the program if threads A and B are executed concurrently?

  1. Consider the following program:

int x;

void f(){ void main(){ while( 1 ){ x = 10; x = x - 1; parbegin( f, f ); x = x + 1; } if( x != 10 ) printf( "x is %d\n", x ); } }

(a) Show a sequence (i.e., trace the sequence of interleavings of statements) such that the statement x is 10 is printed. [5 marks] (b) Show a sequence such that the statement x is 8 is printed. [5 marks] Remember that the increment/decrement at the source language level may not be atomic. For example, the assembly language code: LD R0, x /* load R0 from memory location x / INCR R0 / increment R0 / STO R0, x / store the incremented value back in x */ implements the single C increment instruction x = x + 1.