Week 03

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

A newly created process (still in the state new) at level i can have ______ links to processes at level i+1.

0 Explanation: Child processes are created at runtime, not when a new process is established.

What is the minimum number of physical CPUs an application consisting of 3 processes can utilize?

1 Explanation: Each of the 3 processes can be time-shared on 1 physical CPU.

A process at level i in the process creation hierarchy can have ______ link(s) to processes at the next higher level i-1.

1 Explanation: Except for Root, every process has exactly one parent process at the next higher level.

The set of all PCBs could be implemented as a ________.

1-dimensional array of structures, where the array dimension is the number of available PCB slots. Explanation: The fields of a PCB are of different data types and thus each PCB can be represented by a structure.

What is the minimum number of bits needed to represent the process_state field, if 3 states are supported: running, ready, and blocked?

2 Explanation: 2 bits can represent up to 4 states, which would be sufficient for the states running, ready, and blocked.

What is the minimum number of bits needed to represent the process_state field, if 6 states are supported: running, ready, blocked, new, suspended, and terminated?

3 Explanation: 3 bits can represent up to 8 states, which would be sufficient for the states running, ready, blocked, new, suspended, and terminated.

What is the maximum number of physical CPUs an application consisting of 3 processes can utilize?

3 Explanation: Each of the 3 processes can run on a separate CPU.

On how many virtual CPUs will the 3 processes run?

3 Explanation: Each process can assume having a (virtual) CPU for itself.

The list-free implementation requires ______ fields in the PCB instead of 2 to represent the parent/child relationships.

4 Explanation: The original representation had the fields parent and children. The list-free implementation has the fields parent, child, older sibling, and younger sibling.

Process Control Block (PCB)

A data structure that holds information for a process, including the current instruction address, the execution stack, the set of resources used by the process, and the program being executed. The PCB is the concrete representation of a process.

Ready list

A list containing all processes that are in the ready state and thus are able to run on the CPU. The RL also includes the currently running process. The RL maintains all processes sorted by their importance, which is expressed by an integer value called the priority. The RL can be a simple linked list where the priority of a process is the current position in the list. The RL can also maintain processes in different lists sorted by priorities.

Create process function

Allocates a new PCB, fills the PCB entries with initial values, and links the PCB to other data structures in the system: 1. A new PCB is allocated. The PCB is uniquely identified by a pointer or an array index p. 2. The fields cpu_state, memory, scheduling_information, and accounting_information are filled using the initial values supplied to the function as parameters. 3. Assuming the state transition diagram consists of only the three states, running, ready, and blocked, the process state field is set to ready. 4. The parent field of p is set to point to self, which is the calling process and thus the parent of p. 5. In turn, p is inserted into the calling process's list of children as a new child. 6. The remaining fields are set to NULL, since at creation p has no children, no open files, and no other resources. p is inserted into the RL. 7. The scheduler function is called to select the process to run. Depending on the priorities of the two processes, the scheduler could choose to start the new child process p or to continue the execution of p's parent process.

A modular structuring concept:

An application can generally be divided into multiple tasks, each implemented as a process. Using multiple cooperating processes instead of one has several important advantages: 1. The interfaces between the processes are simple and easy to understand. 2. Each process can be designed and studied in isolation. 3. The implementation reduces idle time by overlapping the execution of multiple processes. 4. Different processes can utilize separate CPUs, if available, thus speeding up the execution.

State Transitions Challenge question: Which of the following state transitions are possible? Blocked -> Running Blocked -> Ready Running -> Suspended Suspended -> Running Running -> Ready Ready -> Blocked

Answers: Blocked -> Ready Blocked -> Suspended Running -> Ready Explanations: Blocked -> Ready: A process must be running in order to make a request and potentially get blocked. When the resource on which process p is blocked becomes available, p becomes ready. Running -> Suspended: A process can be suspended from any of the states: running, ready, blocked. Running -> Ready: A running process may be interrupted and moved to the ready state in order to let other processes use the CPU.

Waiting list

Associated with every resource and contains all processes blocked on that resource because the resource is not available.

When a process p is destroyed, the following choices can be made for p's children: The children are assigned to a specialized OS process (Ex: the init process in Unix) as the new parent.

Beneficial Explanation: This solution allows the child processes to continue executing while still under the control of another process responsible for their eventual termination.

When a process p is destroyed, the following choices can be made for p's children: The children are recursively destroyed along with p.

Beneficial Explanation: This solution prevents the creation of any orphan processes.

Each link in the process creation hierarchy corresponds to a ________.

Bidirectional pointer Explanation: Both directions must be represented so that any process can reach the parent and vice versa.

Reusing PCBs of destroyed processes rather than freeing the data structures is more time-efficient __________.

But less space efficient. Explanation: The PCBs are never freed, so the total space required corresponds to the maximum number of PCBs ever existing concurrently, rather than just the number of currently existing processes.

Virtual CPU

CPU that the process assumes is available only to itself. A virtual CPU can be just an abstraction of the physical CPU or it can be software that emulates the behavior of a different CPU.

CPU state

Consists of all intermediate values held in any CPU registers and hardware flags at the time of the interruption. One of the registers is the program counter, which determines the next instruction to execute after the process is restored.

Decreasing the number of CPUs from 2 to 1 will __________ speed of execution.

Decrease Explanation: All 3 processes will have to time-share the single CPU.

Destroy process function

Destroys a process by freeing the PCB data structure and removing any references to the PCB from the system. Depending on the OS, the destroy function may also destroy all of the process's descendants to prevent having "orphan" processes in the system. The destruction of the entire hierarchy of descendants is accomplished by calling destroy(c) recursively on all children c of p. The destroy() function performs the following steps: 1. After calling destroy(c) on all child processes, remove p from either the RL (when p is ready) or from the waiting list of a resource (when p is blocked). 2. Remove p from the list of children of the calling process. 3. Release all memory and other resources, close all open files, and deallocate the PCB. 4. Call the scheduler to select the next process to run. The call must be made outside of the destroy(p) function to guarantee that the scheduler executes only once, after the entire hierarchy of processes has been destroyed, rather than as part of every recursive call to destroy(c).

When a process p is destroyed, the following choices can be made for p's children: The children could be left without any parent.

Detrimental Explanation: This solution could result in runaway processes (Ex: infinite loops), which would continue using resources but would be hard to detect and eliminate.

The responsibility to close all files should rest with the programmer, not the destroy function.

False Explanation: A process can be destroyed at unpredictable times and the programmer has no way of knowing when files would need to be closed (to prevent any loss of data not yet saved to disk).

The initial value of the process_state field could be set to blocked if memory or some other critical resource is unavailable.

False Explanation: A process enters the blocked state only when requesting an unavailable resource during execution. When a resource is unavailable at creation, the OS would postpone or decline the creation.

When a ready process p wishes to temporarily stop competing for the CPU, p moves itself to the suspended state.

False Explanation: A process in the ready state is not running program code and so cannot perform any actions. Only the OS or p's creator (parent) can move p to the suspended state.

A single RL could not be used with multiple CPUs.

False Explanation: Starting with the highest-priority non-empty list, multiple processes can be marked as running in the RL. Ex: With 2 CPUs, the processes at level n and 7 in the above example could both be in the running state.

A context switch for a currently running process p may be caused by some other process q.

False Explanation: The OS can take the CPU away from a running process p, or p can give up the CPU by requesting an unavailable resource. But some other process q cannot cause a context switch for process p.

The PCB is created by the process when execution starts.

False Explanation: The PCB is a data structure created and maintained only by the OS, not by the process itself.

The PCB data structure could be reduced if a process could generate only one child at a time.

False Explanation: The children field is a pointer to the first child in the list. The restriction would eliminate dynamic memory management but the same pointer to the first child process would still be needed.

The initial CPU state of a newly created process is NULL or undefined.

False Explanation: The program counter must be set to the starting address. Also, the stack pointers must be set to point to the top of the stack. Other registers and flags are generally set to 0.

When a newly created process p is ready to compete for the CPU, p moves itself from the new to the ready state.

False Explanation: The purpose of the new state is to allow the OS to control how many processes are competing for the CPU and thus only the OS can cause a transition from new to ready.

The main purpose of virtual CPUs is to improve the performance of a system.

False Explanation: Virtual CPUs allow processes to transparently share a physical CPU, generally at the cost of reduced speed. Virtual CPUs also allow processes to run different physical CPUs without code modification or recompilation.

When a blocked process p is suspended and the resource needed by p becomes available, p is moved to the ready state.

False Explanation: p is suspended for a reason different from waiting for a resource. Thus p must remain in the suspended state until explicitly reactivated. Only then is the process moved to the ready state.

The PCB becomes part of the program being executed by a process.

False The PCB is an independent data structure managed by the OS that is destroyed when the process terminates. The program remains unchanged.

An application running on multiple physical CPUs must be modified in order to run correctly on a single CPU.

False: Explanation: A process can run on a dedicated CPU or with interruptions on a shared CPU. The context switches are transparent to the process, and the results are unaffected.

Process creation hierarchy

Graphical representation of the dynamically changing parent-child relationships among all processes. The process creation hierarchy changes each time a process is created or destroyed.

Increasing the number of CPUs from 2 to 3 will __________ speed of execution.

Increase Explanation: Each of the 3 processes can now have a separate physical CPU.

Benefits of virtual CPUs

Independence from the number and type of CPUs provides several crucial benefits: Multi-user support: Multiple users, each represented by one or more separate processes, can share the same machine without being aware of each other. Multi-CPU transparency: An application written to utilize multiple CPUs will run correctly, although perhaps more slowly, if only one CPU is available. Portability: An application compiled for one type of CPU can run on a different CPU without being modified or even recompiled.

Process

Instance of a program being executed by an OS. Ex: When a user opens a new application like a web browser or text editor, the OS creates a new process.

Indicate which PCB fields may change during a process's lifetime. CPU_state

May change Explanation: The CPU_state changes during every context switch.

Indicate which PCB fields may change during a process's lifetime. memory

May change Explanation: The amount of memory needed by a process typically varies over time and is adjusted accordingly.

Indicate which PCB fields may change during a process's lifetime. children

May change Explanation: The process can create and destroy multiple children at run time.

Indicate which PCB fields may change while a process is in the running state. children

May change Explanation: The process can create and destroy multiple children at run time.

Indicate which PCB fields may change during a process's lifetime. open_files

May change Explanation: The process can open and close any number of files during execution.

Indicate which PCB fields may change while a process is in the running state. open_files

May change Explanation: The process can open and close any number of files during execution.

Indicate which PCB fields may change during a process's lifetime. process_state

May change Explanation: The process_state keeps changing as the process requests resources or is moved to/from the CPU

The list-free implementation is ________ the linked-list implementation.

More time efficient than Explanation: The main reason for the list-free implementation was to improve time-efficiency by avoiding the dynamic memory management needed for the linked lists.

The create() function fills the various fields of p's PCB from different sources. Identify the correct source for each given sample field.

No definition. Refer to the image.

State Transitions Challenge question: Select the correct function for the state transition Blocked -> Running.

None Explanation: Only a ready process may be selected to run.

State Transitions Challenge question: Select the correct function for the state transition Suspended -> Running.

None Explanation: Only a ready process may be selected to run.

State Transitions Challenge question: Select the correct function for the state transition Ready -> Blocked

None Only a running process is able to request a resource and potentially become blocked.

Increasing the number of CPUs further from 3 to 4 will __________ speed of execution.

Not affect Explanation: Each process can only use one CPU and thus only 3 CPUs can be utilized.

State Transitions Challenge question: Select the correct function for the state transition Running -> Ready.

OS Scheduler Explanation: A running process may be interrupted and moved to the ready state in order to let other processes use the CPU.

State Transitions Challenge question: Select the correct function for the state transition Ready -> Running.

OS Scheduler Explanation: The scheduler may select the process to run next and change the process state to Running.

Process 3 creates a child process, process 8. Complete the resulting table.

Process 3 is the parent of the new process 8 and, in turn, process 8 is the child of process 3. All other pointers remain unchanged.

Process 6 is deleted. Complete the resulting table.

Process 4 continues as the parent of processes 5 and 3. The younger sibling of 5 is 3 and the older sibling of 3 is 5. Process 4's child pointer points to process 5.

The diagram shows the parent-child relationships among six processes. (The parent links have been omitted for clarity.) Complete the table by showing which field points to which process using the four different pointers. If an entry is unknown, enter -.

Processes 0 and 2 are children of process 7: the parent field of both is 7. Processes 4, 5, and 8 are children of process 2: the parent field of all three is 2. Process 0 is the first child of 7 and process 4 is the first child of 2. Processes 0 and 2 are linked together via the ys/os pointers. Processes 4, 5, and 8 are similarly linked together via the ys/os pointers.

Process 2 creates a child process. Complete the resulting table. Complete the table by showing which field points to which process using the four different pointers. If an entry is unknown, enter -.

Processes 1, 3, and 7 are all children of process 2 and thus the parent field of all three is 2. Process 3 gains process 7 as a younger sibling and, in turn, 3 becomes the older sibling of 7. All other pointers remain unchanged.

The following diagram shows the parent-child relationships among three processes. Linked lists can be avoided by implementing two additional pointers, younger sibling (ys) and older sibling (os), in each PCB. Complete the table by showing which field points to which process using the four different pointers. If an entry is unknown, enter -.

Processes 7 and 6 are children of process 0: the parent field of both points to 0. Process 7 is the older sibling of 6 and, in turn, process 6 is the younger sibling of 7. ${table}

State Transitions Challenge question: Select the correct function for the state transition Suspended -> Blocked.

Reactivate Explanation: When a process suspended in the Blocked state is reactivated, the process is moved back to the Blocked state.

State Transitions Challenge question: Select the correct function for the state transition Suspended -> Ready

Reactivate Explanation: When a process suspended in the Ready state is reactivated, the process is moved back to the Ready state.

Physical CPU

Real hardware instance of a CPU. Multiple processes may run on one physical CPU using a technique known as time sharing.

State Transitions Challenge question: Select the correct function for the state transition Blocked -> Ready.

Resource Release Explanation: When the resource on which the process is blocked is released, the process becomes ready to run.

State Transitions Challenge question: Select the correct function for the state transition Running -> Blocked

Resource Request Explanation: If a running process requests a currently unavailable resource, the process becomes blocked.

The transition (blocked -> ready) of a process p is caused by _____.

Some other process. Explanation: p is waiting for a resource held by or generated by some other process q. The release of the resource or data by q causes the transition of p back to ready.

When the CPU with floating operations is replaced with a CPU without floating point operations, then __________.

Speed of execution may change. Explanation: The virtual CPU software will implement the same operations as the hardware but the hardware implementation is likely to be faster.

State Transitions Challenge question: Select the correct function for the state transition Blocked -> Suspended.

Suspend Explanation: A process can be suspended from any of the running, ready, or blocked states.

State Transitions Challenge question: Select the correct function for the state transition Running -> Suspended

Suspend Explanation: A process can be suspended from any of the running, ready, or blocked states.

State Transitions Challenge question Select the correct function for the state transition Ready -> Suspended.

Suspended? Explanation: A process can be suspended from any of the running, ready, or blocked states.

The transition (ready -> running) of a process p is caused by _____.

The OS. Explanation: Only the OS can decide when a process should continue to run.

The transition (running -> ready) of a process p is caused by _____.

The OS. Explanation: The OS may wish to let some other process use the CPU.

The PCB data structure

The entries of a PCB are composed of different data types, including integers, characters, or pointers. Consequently, each PCB is implemented as a heterogeneous data structure. Ex: "struct" in the C language.

In parts (b) and (c) of the animation, _________.

The physical CPUs have different instruction sets. Explanation: The processes can run on different physical CPUs using virtual CPUs.

The transition (running -> blocked) of a process p is caused by _____.

The process p itself. Explanation: p causes the transfer when requesting a currently unavailable resource.

Adding a new child process with the list-free implementation uses _____ the linked-list implementation.

The same amount of memory as Explanation: Two pointers are required per child with either implementation. With a linked-list, the 2 pointers are in a linked-list node. With the list-free implementation, the 2 pointers are added to the PCB. So the memory usage is the same.

Context switch

Transfer of control from one process to another.

When PCBs are allocated and freed dynamically, the overhead of the dynamic memory management could be reduced by reusing PCBs of destroyed processes.

True Explanation: A PCB of a destroyed process could be reused by marking the slot in the pointer array with a new state (for example, "available"), instead of freeing the PCB data structure and setting the pointer to NULL.

Two processes can be executing the same program.

True Explanation: A program can be executed multiple times simultaneously, each instance being a process. Each PCB has a separate program counter to keep track of each process' execution location in the program.

The transition of a process p from running to terminated can be caused by p itself.

True Explanation: Completing all work or causing a fatal error causes p to transition from running to terminated.

With RL implemented as a priority list, the range of priorities is [n1:n2], where n1 and n2 can be: n1 < 0, n2 > 0

True Explanation: Depending on the implementation's needs, the range can start and end with any integer, including negative integers. Ex: [-5:5] provides 11 priority levels, where the positive range and the negative range could be given special significance, such as differentiate between interactive and background processes.

When a new process p is created, the scheduler could select p to run next.

True Explanation: If p's priority is higher than or equal to the priority of p's parent, then p could be chosen by the scheduler.

Any process is either on the RL and in the ready or running state, or on a resource's waiting list and in the blocked state. To efficiently find on which lists p resides, additional information must be kept in the PCB.

True Explanation: Only one RL, but potentially many waiting lists, exist in the system. To find the relevant list quickly, the PCB must maintain a pointer to the current list.

An OS uses a PCB to represent a process.

True Explanation: The OS implements every process as a data structure called PCB, the process control block.

A context switch for a currently running process p may be caused by the OS.

True Explanation: The OS may wish to let another process q use the CPU.

The 2-process design reduces the number of context switches necessary for the periodic checking of brick availability at the factory.

True Explanation: The mason can keep working as long as the pallet is not empty. The supply is handled by the separate truck driver, which is blocked except when moving bricks from the factory or unloading bricks.

With RL implemented as a priority list, the range of priorities is [n1:n2], where n1 and n2 can be: n1 = 0, n2 > 0

True Explanation: The most common choice is to start the range with n1 = 0 and chose n2 to provide the desired number of priority levels. Ex: [0:7] provides 8 priority levels.

With RL implemented as a priority list, the range of priorities is [n1:n2], where n1 and n2 can be: n1 = 0, n2 = 0

True Explanation: The range can be [0:0], in which case the priority list degenerates to a single linked list.

A context switch for a currently running process p may be caused by process p itself.

True Explanation: This context switch may occur when process p requests a currently unavailable resource.

The 2-process design permits the mason and the driver to operate in parallel.

True Explanation: When 2 workers are available, the process of laying bricks and the process of driving bricks can be done at the same time.

Organizing PCBs

Two ways exist to organize all PCBs: 1. An array of structures. The PCBs are marked as free or allocated, which eliminates the need for any dynamic memory management. The main drawback is a lot of wasted memory space to maintain a sufficient number of PCB slots. 2. An array of pointers to dynamically allocated PCBs. The pointer array wastes little space and can be made much larger than the array of structures. The drawback is the overhead of dynamic memory management to allocate each new PCB and to free the memory when the process terminates.

The PCB contains an up-to-date copy of the CPU state of a process p _____ .

When p's state is ready or blocked. Explanation: At this point, p's PCB contains an exact copy of the CPU state at the point when p transitioned out of the running state. This CPU state is restored when p transitions back to the running state.

Indicate which PCB fields may change while a process is in the running state. CPU_state

Will not change Explanation: The CPU_state is copied into the CPU when the process starts running and is not updated until the process stops again.

Indicate which PCB fields may change while a process is in the running state. parent

Will not change Explanation: The parent is the creator of the current process and by definition cannot change.

Indicate which PCB fields may change while a process is in the running state. process_state

Will not change Explanation: The process_state is set to "running" when the process starts running and changes to "ready" or "blocked" only when the process stops running.

What would be the most space-efficient data type to represent the process_state in C?

char Explanation: Each character is a single byte or 8 bits and can represent up to 2^8 different states.

When a process p is moved from the current state (running, ready, or blocked) to the suspended state, then upon reactivation, ________.

p is moved to either the ready or blocked state


Kaugnay na mga set ng pag-aaral

Chapter 9 -- Dairy Products on the Menu

View Set

Reading - Treasure of Lemon Brown Study Guide

View Set

Psychology 1010 - Module 11 Memory

View Set