CPT104操作系统笔记(Lecture1)

1.Overview

1.1 What is Operating System?

An operating system is a program that manages a computer’s hardware. Italso provides a basis for application programs and acts as an intermediary between the computer user and the computer hardware.
OS carry out the most commonly required operations:
1. Process Management
2. Memory Management
3. File System Management
4. IO System Management
5. Protection and Security

1.2 What Operating Systems Do?

1.3 Computer-System Architecture

(1)Single-Processor Systems

(2)Multiprocessor Systems

(3)Clustered Systems (集群系统)
Differences between (2)&(3):
Clustered systems differ from the multiprocessor systems in that they are composed of two or more individual systems—or nodes—joined together. Such systems are considered loosely coupled(松散耦合) .

2. Process

(textbook Chapter3)

2.1 process concept

an operating system executes a variety of programs:
  Batch system (批处理系统) - jobs
  Time-shared system (分时系统) - user programs or tasks
A program in execution is a process . Process execution must progress in sequetial fashion.
A program is a passive entity(e.g.保存在磁盘上的文件), whereas a process is an active entity.
Process include: program code(text section), current activity, the process stack (含临时数据,如函数参数、返回地址和局部变量), a data section, aheap (在进程运行时期间动态分配的内存).

One instruction at most is executed on behalf of the process.
Program becomes process when executable file loaded into memory.

2.1 process state

As a process executes, it changes state .
The state of a process is defifined in partby the current activity of that process. A process may be in one of the following states:
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 fifinished execution.

2.2 Process Control Block (PCB)

进程控制块

PCB is a data structure used for storing the information about a process.

Every process is identified by its own PCB.

include:Process state, program counter, CPU registers, CPU-scheduling information, memory-management information, accounting information, I/O status information.

PCB of each progress resides in(存在于)the main memory and are present in a linked list.

PCB is important in multiprogramming environment as it captures(捕捉) the information pertaining to (有关)the number of processes running simultaneously.

2.3 Process Scheduling

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

Scheduling Queues

process enter system -> put into a job queue( consists of all processes in the system)
The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue .
The list of processes waiting for a particular I/O device is called a device queue . Each device has its own device queue

Schedulers (select processes from the queues)

long-term scheduler (job scheduler) controlling the Degree of Multiprogramming.(e.g. the total number of processes that are present in the ready state)
short-term scheduler (CPU scheduler) selecting one process from the ready state for scheduling it on the running state
这两个调度器之间的主要区别在于执行的频率。短期调度器必须频繁地为CPU选择一个新进程。进程在等待I/O请求之前可能只执行了几毫秒。通常,短期调度器每次至少执行一次100毫秒。因为执行之间的时间很短,所以短期调度器必须很快。如果决定执行一个进程100毫秒需要10毫秒,那么10/(100 + 10)= 9%的CPU被使用
如果多道程序的程度是稳定的,那么进程的平均创建速率必须等于进程离开系统的平均离开速率。因此,可能只有在 进程离开系统时才需要调用长期调度器。由于执行间隔较长,长期调度器可以花更多的时间来决定应该选择哪个进程执行。
medium-term scheduler (added if degree of mutiple programming needs to decrease) swapping of a process from the main memory to secondary memory and vice-versa.

Context Switch

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 and load the saved stated for the new process via a context switch.

 Context-switch times are highly dependent on hardware support.

2.4 Operations on Processes

Process Creation

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

each process has a unique process identifier(or pid)

Resource sharing options

1. parent and children share all/no resources

2. children share subset of parent's resources

Execution options

1. parent and children execute concurrently

2. parent waits until children terminate

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.
        the process may return a status value (typically an integer) to its parent process(via the          wait() system call)
        All the resources of the process are deallocated by the operating system.
A parent may terminate the execution of one of its children for a variety of reasons

2.5 Interprocess Communication

A process is independent if it cannot affect or be affected by the other processes (does not share data with any other process).
A process is cooperating if it can affect or be affected by the other processes ( shares data with other processes )
why cooperating processes are allowed:
Information sharing
Computation speedup
Modularity
Convenience

Interprocess communication models:

message passing and shared memory
Message passing is useful for exchanging smaller amounts of data , because no conflicts need be avoided.
Message passing is easier to implement in a distributed system.
Shared memory can be faster than message passing

Shared-Memory Systems

A region of memory is shared by cooperating processes(like producer and consumer processes).
Process can exchange information by reading and writing all the data to the shared region.
Buffers(缓冲区):
The unbounded buffer places no practical limit on the size of the buffer. ( The consumer may have to wait for new items, but the producer can always produce new items. )
The bounded buffer assumes a fixed buffer size. ( the consumer must wait if the buffer is empty, and the producer must wait if the buffer is full. )

Message-Passing Systems

Message passing provides a mechanism to allow processes to communicate and to synchronize their actions without sharing the same address space.
messages exchanged among the cooperating processes
A message-passing facility provides at least two operations:
send (message)       receive (message)

The message size is either fixed or variable.

If processes P and Q want to communicate,a communication link must exist between them.

methods for logically implementing a link and the send() / receive() operations:
Direct or indirect communication
Synchronous or asynchronous communication
Automatic or explicit buffering
Direct or indirect communication
exchange messages by communicating processes reside in a temporary queue
Buffering
zero capacity: the queue has a maximum length of zero (the link cannot have any messages waiting in it)
bounded capacity: the queue has finite length n (at most n messages can reside in it)
unbounded capacity: the queue's length is potentially infinite.
direct communication
Each process must explicitly name the recipient or sender of the communication
send(P, message) —Send a message to process P .
receive(Q, message) —Receive a message from process Q .
implemented when the processes use specific process identifier for the communication.
difficult to identify the sender ahead of time
indirect communication
the messages are sent to and received from mailboxes , or ports .
create a new mailbox(port)
send(A, message) —Send a message to mailbox A .
receive(A, message) —Receive a message from mailbox A
destroy a mailbox
Synchronous or asynchronous message passing
Message passing may be either blocking or nonblocking ( synchronous and asynchronous .)
Blocking send . The sending process is blocked until the message is received
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.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值