본문 바로가기

Operating System Design

Operating System Design - Processes

Process Concept

 

Process : a program in execution; process execution must progress in sequential fashion

   program code (text section), program counter, processor registers, Stack containing temporary data, Data section     containing global variables, Heap containing memory dynamically allocated during run time

One program can be several processes

 

Process State

 

New : The process is being created

Running : Instructions are being executed

Waiting : The process is waiting for some event to occur

Ready : The process is waiting to be assigned to a processor

Terminated : The process has finished execution

Process Control Block (PCB)

 

Process state : running, waiting ...

Program counter : location of instruction to next execute

CPU registers : contents of all process-centric registers

CPU scheduling information : priorities, scheduling queue pointers

 

Threads

 

Process has a single thread of execution

Multiple locations can execute at once (Multiple threads of control => threads)

Must then have storage for thread details, multiple program counters in PCB

 

Process Scheduling

 

Process scheduler selects among available processes for next execution on CPU core

 

Ready queue  : set of all processes residing in main memory, ready and waiting to execute

Wait queues : set of processes waiting for an event

CPU Switch

 

A context switch occurs when the CPU switches from one process to another

When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch

Context of a process represented in the PCB

 

Multitasking in Mobile Systems

 

Some mobile systems allow only one process to run, others suspended

   Single foreground process : controlled via user interface

   Multiple background processes : in memory, running, but not on the display, and with limits

 

Process Creation

 

Parent process create children processes, which, in turn create other processes, forming a tree of processes

Generally, process identified and managed via a process identifier (pid)

 

In UNIX

   fork() system call : creates new process

   exec() system call used after a fork() to replace the process’ memory space with a new program

   Parent process calls wait() for the child to terminate

 

Process Termination

 

Process executes last statement and then asks the operating system to delete it using the exit() system call

   Returns status data and pid of the terminated process from child to parent (via wait())

   Process’ resources are deallocated by operating system

Parent may terminate the execution of children processes using the abort() system call

   Child has exceeded allocated resources

   Task assigned to child is no longer required

   The parent is exiting and the operating systems does not allow a child to continue if its parent terminates

 

Cascading termination : Some operating systems do not allow child to exists if its parent has terminated. If a process terminates, then all its children must also be terminated

 

If no parent waiting (did not invoke wait()) process is a zombie

If parent terminated without invoking wait , process is an orphan

 

Interprocess Communication

 

Processes within a system may be independent or cooperating

Cooperating processes need inter-process communication (IPC)

Two models of IPC : Shared memory & Message passing

Producer-Consumer Problem

 

Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process

Unbounded-buffer places no practical limit on the size of the buffer

Bounded-buffer assumes that there is a fixed buffer size

 

Interprocess Communication

 

Shared Memory : An area of memory shared among the processes that wish to communicate

The communication is under the control of the user processes not the operating system

Major issues is to provide mechanism that will allow the user processes to synchronize their actions when they access shared memory

 

Message Passing : Mechanism for processes to communicate and to synchronize their actions

If processes P and Q wish to communicate, they need to:

   Establish a communication link between them, Exchange messages via send/receive

Implementation of communication link : 

Physical : Shared memory, hardware bus, network

Logical : Direct or indirect, Synchronous or asynchronous, Automatic or explicit buffering

 

Direct Communication : 

 

send (P, message) : send a message to process P

receive(Q, message) : receive a message from process Q

 

A link is associated with exactly one pair of communicating processes

The link may be unidirectional, but is usually bi-directional

 

Indirect Communication : 

 

send(A, message) : send a message to mailbox A

receive(A, message) : receive a message from mailbox A

Each mailbox has a unique id

Processes can communicate only if they share a mailbox

A link may be associated with many processes

Link may be unidirectional or bi-directional

 

Synchronization : 

Blocking is considered synchronous

Blocking send : the sender is blocked until the message is received

Blocking receive : the receiver is blocked until a message is available

Non-blocking is considered asynchronous

Non-blocking send : the sender sends the message and continue

Non-blocking receive : the receiver receives a valid message, or null message

 

Buffering : 

Zero capacity : no messages are queued on a link. Sender must wait for receiver (rendezvous)

Bounded capacity : finite length of n messages Sender must wait if link full

Unbounded capacity : infinite length Sender never waits

 

Pipes

 

Acts as a conduit allowing two processes to communicate

Ordinary pipes : cannot be accessed from outside the process that created it

Typically, a parent process creates a pipe and uses it to communicate with a child process that it created

Ordinary Pipes allow communication in standard producer-consumer style

Producer writes to one end (the write-end of the pipe)

Consumer reads from the other end (the read-end of the pipe)

Require parent-child relationship between communicating processes

 

Named pipes : can be accessed without a parent-child relationship

 

Sockets

 

A socket is defined as an endpoint for communication

Concatenation of IP address and port : a number included at start of message packet to differentiate network services on a host

The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8