!!!Chapter 3 Process Concept

3.1 Process Concept

A process is a program in execution.

3.1.1 The Process

A process contains several parts:

text section: the program code

process stack: contains temporary data

data section: contains global variable

heap: dynamically allocated memory

program counter: specify the next instruction to execute

3.1.2 Process State

New: The process is being created

Running: Instructions are being executed

Waiting: The process is waiting for some event to occur (such as an I/O completion or reception of a signal)

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

Terminated: The process has finished execution

Only one process can be running on any processor at any instant. Many processes may be ready and waiting.

3.1.3 Process Control Block            P 104

In general, the PCB serves as the repository for any information that may vary from process to process.

3.2 Process Scheduling

The process scheduler selects an available process (possibly from a set of several available processes) for program execution on the CPU.

3.2.1 Scheduling Queues

When process enter the system, they are put into a job queue.

The processes that are residing in main memory and are ready and waiting to execute are kept in theready queue.

The list of processes waiting for a particular I/O device is called a device queue.

A common representation of process scheduling is a queueing diagram:

3.2.2 Schedulers

The process selection is carried out by the appropriate scheduler.

Normally, more processes are submitted than can be processed. These processed are spooled to a mass-storage. Thelong-term scheduler(job scheduler) selects processes from the pool and loads them into memory. The short-term scheduler(CPU scheduler) selects from among the processes that are ready to execute and allocate the CPU to one of them.

long-term scheduler controls the degree of multiprogramming (the number of processes in memory)

There are two types of processes:

I/O-bound process: spends more of its time doing I/O than computations.

CPU-bound process: spends more time doing computation.

The long-term scheduler should select a good process mix of I/O-bound and CPU-bound processes.

medium-term scheduler/context switch P 109 - 110

3.3 Operations on Processes

3.3.1 Process Creation

A process may create several new processes during the course of execution. The creator isparent process, the new processes are children of that process. They will form atree of processes.

Operating systems identify processes according to a unique process identifier (pid)

Subprocesses may obtain resources directly from the OS or it may be constrained to a subset of the resources of the parent process. Restricting a child process to a subset of the parent's resources prevents any process from overloading the system by creating too many subprocesses.

Execution possibilities:

1. The parent continues to execute concurrently with its children

2. The parent waits until some or all of its children have terminated.

Address space possibilities:

1. The child process is a duplicate of the parent process (it has the same program and data as the parent)

2. The child process has a new program loaded into it

3.3.2 Process Termination

A process terminates when it finishes executing its final statement and asks the operating system to delete it by using the exit() system call.

A process(normally the parent process) can cause the termination of another process via an appropriate system call.

3.4 Interprocess Communication

A process is independent if it cannot affect or be affected by the other processes executing in the system. Otherwise, it's cooperating.

Cooperating processes require an interprocess communication(IPC) mechanism. There are two models of IPC: 1)shared memory, 2)message passing

3.4.1 Shared-Memory Systems

Typically, a shared-memory region resides in the address space of the process creating the shared-memory segment.

producer-consumer problem: A producer process produces information that is consumed by a consumer process.

To allow producer and consumer processes to run concurrently, we must have available a buffer of items that can be filled by the producer and emptied by the consumer.

There are two types of buffers:

unbounded buffer: producer don't need to wait, consumer need to wait if buffer is empty

bounded buffer: producer need to wait if buffer is full, consumer need to wait if buffer is empty

3.4.2 Message-Passing Systems

Message-passing allow processes to communicate and synchronize their actions without sharing the same address space.

A message-passing facility provides at least two operations: send and receive

fixed size message: system-level implementation is easy, programming is difficult

variable size: system-level implementation is hard, programming is easy.

Communication link logical implementation:

1. Direct or indriect communication

2. Synchronous or asynchronous communication

3. Automatic or explicit buffering

3.4.2.1 Naming

Under direct communication, each process that wants to communicate must explicitly name the recipient or sender of the communication.

symmetry scheme: send(P, message), receive(Q, message)

asymmetry scheme: send(P, message), receive(id, message)

- Changing the id of a process need to examining all other process definition.

With indirect communication, the message are sent to and received frommailboxes, orports.

Each mailbox has a unique identification.

3.4.2.2 Synchronization

Message passing may be either blocking or nonblocking--- as known assynchronous and asynchronous.

  • Blocking send. The sending process is blocked until the message is received by the receiving processes or by the mailbox
  • Nonblocking send. The sending process sends the message and resumes operation.
  • Blocking receive. The receiver blocks until a message is available
  • Nonblocking receive. The receiver retrieves either a valid message or a null.

3.4.2.3 Buffering

message exchanged by communicating processes reside in a temporary queue

  • Zero capacity. Sender must be blocked until the recipient receives the message
  • Bounded capacity. At most n messages can reside in it. Sender is blocked when queue is full
  • Unbounded capacity. Sender is never blocked.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值