View on GitHub

Notes

reference notes

What is a Process?

As we have seen in the Overview section, a process is the executing entity when the processor begins to execute the program code. Components of a process include the following:

Process Elements

Let us suppose the processor begins to execute this program code, and we refer to this executing entity as a process. At any given point in time, while the program is executing, this process can be uniquely characterized by a number of elements, including the following:

Process Control Block

Process States

During program execution, a process is created for that program.

Overtime, the program counter may refer to code on different programs that are part of different processes.

We can characterize the behavior of a process by listing the sequence of instructions that execute for that process. the behavior of the processor can be characterized by showing how the traces of the various processes are interleaved

Dispatcher: small program that switches the processor from one process to another.

Process creation and termination

4 reasons for process creation: Reason | Description —|— New batch job | The OS is provided with a batch job control stream, usually on tape or disk. When the OS is prepared to take on new work, it will read the next sequence of job control commands. Interactive log-on | A user at a terminal logs on to the system. Created by OS to provide a service | The OS can create a process to perform a function on behalf of a user program, without the user having to wait (e.g., a process to control printing). Spawned by existing process | For purposes of modularity or to exploit parallelism, a user program can dictate the creation of a number of processes.

Process termination: There must be a means for a process to indicate its completion

  1. A batch job should include a HALT instruction or an explicit OS service call for termination
  2. For an interactive application, the action of the user will indicate when the process is completed (e.g. log off, quitting an application)

Reasons for process termination:

Two-State Process Model

In this model, a process may be in one of the two states: Running or Not Running.

How it works:

Queuing Diagram

Queuing Diagram Processes that are not running must be kept in some sort of queue, waiting their turn to execute.

There is a single queue in which each entry is a pointer to a particular process.

A process that is interrupted is transferred to the queue of waiting processes. Alternatively, if the process has completed or aborted, it is discarded (exits the system). In either case, the dispatcher takes another process from the queue to execute.

The queue is first in first out (FIFO) list and the processor operates in Round robin.

Leading to Five-State Process Model:

We can solve this by splitting the “Not Running” state into two states:

now instead of two states, we have five states by adding another two states “new” and “exit” that are useful for process management.

Five-State Process Model

Process State Description
New a process that has just been created but not yet admitted to the pool of executable processes by the OS. typically, a new process has not yet been loaded into main memory., although its process control block has been created.
Ready a process is ready to execute when given the opportunity.
Running the process is currently executing.
Blocked a process that cannot execute until some event occurs or completes.(events include I/O operations, waiting for OS services)
Exit a process that has been released from the pool of executable processes by the OS, either because it halted or aborted for some reason.

Using Two Queues

Two Queues

As each process is admitted to the system, it is placed in the Ready queue. When it is time for the OS to choose another process to run, it selects one from the Ready queue.

When a running process is removed from execution, it is eitherterminated or placed in the Ready or Blocked queue, depending onthe circumstances

Finally, when an event occurs, any process in the Blocked queue that has been waiting on that event only is moved to the Ready queue.

Suspended Processes

When the process need to be executed all the processes components need to be in the main memory.

Processor is faster than I/O operation, all processes could be waiting for I/O.

Thus even with multiprogramming, processor could be idle most of the time.

How to solve it?

Swapping

Characteristics of a Suspended Process:

One suspend state

After the OS swaps-out a process from blocked state to suspend state, it brings back a previously suspended process into main memory.

the problem with this is that all of the processes that have been suspended were in the Blocked state at the time of suspension. It clearly would not do any good to bring a blocked process back into main memory, because it is still not ready for execution. Recognize, however, that each process in the Suspend state was originally blocked on a particular event. When that event occurs, the process is not blocked and is potentially available for execution.

Therefore, we need to rethink this aspect of the design. leading us to the two suspend state model.

Two suspend states

There are two independent concepts here: whether a process is waiting on an event (blocked or not), and whether a process has been swapped out of main memory (suspended or not). To accommodate this 2×2 combination, we need four states:

Reasons for process suspension

Reason Description
Swapping The OS needs to release sufficient main memory to bring in a process that is ready to execute.
Other OS reason The OS may suspend a background or utility process or a process that is suspected of causing a problem.
Interactive user request A user may wish to suspend execution of a program for purposes of debugging or in connection with the use of a resource.
Timing A process may be executed periodically (e.g., an accounting or system monitoring process) and may be suspended while waiting for the next time interval.
Parent process request A parent process may wish to suspend execution of a descendent to examine or modify the suspended process, or to coordinate the activity of various descendants.

Process Description

The OS contorls events within computer system. Schedules and dispatches processes for execution by the processor, allocates resources(memory, i/o devices, files) to processes and responds to requests by user processes for basic services.

For the OS to manage the processes and resources, it must have information about the current status of each process and resource.

Tables are constructed for each entity the operating system manages. these tables are called OS control tables.

OS Control Tables

Memory tables

Must include:

I/O tables

If an I/O operation is in progress, the OS needs to know:

File tables

Much, if not all, of this information may be maintained and used by a file management system, in which case the OS has little or no knowledge of files. In other operating systems, much of the detail of file management is managed by the OS itself.

Process tables

In order to manage and control a process the OS must know:

  1. Process attributes, what a process is
  2. Process location, where a process is

Process location

A process will need sufficient memory to hold the programs and data of that process.

The execution of a program typically involves a stack that is used to keep track of procedure calls and parameter passing between procedures.

Keeping track of the Process Location requires good memory management by the OS.

Process image

The collection of program, data, stack, and attributes is referred to as the process image.

ElementS of a process image:

Process image location will depend on the memory management scheme being used

To execute a process, the ENTIRE process image must be loaded onto memory.

Process Control

Modes of Execution

User mode Kernel mode
User program executes in user mode Monitor executes in kernel mode
Certain areas of memory are protected from user access Protected areas of memory may be accessed
Certain instructions may not be executed Privileged instructions may be executed
Less privileged More privileged

Why two modes?

How does the processor know which mode it is to be executed? Using a bit in PSW (program status word) that indicates the mode of execution.

How the mode is change? Bit changed in response to certain event:

What happens during Process Creation?

Once the OS decides to create a new process it:

  1. assigns a unique process identifier to the new process
  2. allocates space for the process
  3. initializes the process control block
  4. sets the appropriate linkages
  5. creates or expands other data structures

Process Switching

A process switch may occur any time when the OS has gained control from the currently running process.

Process switch (change) from one state to another state. E.g. A running process is interrupted and the OS assigns other process to the Running state and give control to the process.

issues:

  1. What events trigger a process switch?
  2. Must recognize the distinction between mode switching and process switching?
  3. What must the OS do to the various data structures under its control to achieve process switch?

What events trigger a process switch?

  1. Interrupts

Due to some sort of event that is external to and independent of the currently running process

  1. Trap

An error or exception condition generated within the currently running process

OS determines if the condition is fatal

  1. Supervisor Call

OS activated by a supervisor call from the program being executed

Example:

Must recognize the distinction between mode switching and process switching?

Mode switching may happen if the interrupt is not produce a process switch.

The control can just return to the interrupted program.

Then only the processor state information needs to be saved on stack

Less overhead: no need to update the PCB like for process switching

Mode Switching:

If no interrupts are pending the processor:

If an interrupt is pending the processor:

What must the OS do to the various data structures under its control to achieve process switch?

If the currently running process is to be moved to another state (Ready, Blocked, etc.), then the OS must make substantial changes in its environment.

Steps in process switching:

  1. save the context of the processor
  2. update the process control block of the process currently in the Running state
  3. move the process control block of this process to the appropriate queue
  4. select another process for execution
  5. update the process control block of the process selected
  6. update memory management data structures
  7. restore the context of the processor to that which existed at the time the selected process was last switched out

Security Issues

A key security issue in the design of any OS is to prevent, or at least detect, attempts by a user or a malware from gaining unauthorized privileges on the system and from gaining root access.

An OS associates a set of privileges with each process

Typically a process that executes on behalf of a user has the privileges that the OS recognizes for that user

Highest level of privilege is referred to a root access or administrator or supervisor

Two System Access Threats

Intruders

Malicious software

Countermeasures

  1. Intrusion Detection
  2. Authentication
  3. Access Control
  4. Firewalls