Operating System - basics summary (a)

Results of their own still learning ... The following notes are from other bloggers, also has its own collection of


 

1, the operating system of the four characteristics

1) concurrently: executing a plurality of programs within the same time

      The difference between parallel and concurrent:

    Parallel: two or more events occur at the same time, have the ability to handle multiple tasks simultaneously

    Concurrency: the ability of two or more events occur at the same time interval, there must handle multiple tasks, not necessarily at the same time 

    *understanding:

           

2) Sharing: system resources can be memory, process multiple concurrent threads of execution used together.

3) Virtual: time division multiplexing (e.g. Time-Sharing System) and spatial division multiplexing (e.g., virtual system) technology, to a physical entity, a plurality of virtual.

4) Asynchronous: The system is in the process of execution of stop-go manner and at an unpredictable rate of advance.

       Synchronous and asynchronous:

    Sync: refers to a process in the implementation of a request, if the request is take some time to return information, then this process will wait forever, knowing that receives return information only continue execution. That is, according to the order of execution , perform a completion before the next one

    Asynchronous: refers to the process do not need to wait forever , but continue to do the following, regardless of the state of other processes.

 

2, process and thread

2.1 Concepts

1) Process

  Is executing a program, that is, once the program is loaded into memory and ready to perform, it is a process (task). The basic concept of the process is to identify the resource allocation, but also is the basic unit is scheduled to run, is a unit of concurrent execution of the system.

2) Thread

  The implementation of a single process for each task is a thread. A thread is the smallest unit of execution process kinds of operations.

  You can create multiple threads simultaneously on a process

*understanding:

* Links: https://www.liaoxuefeng.com/wiki/897692888725344/923056118147584

 

More than 2.2 task concept

  Multitasking operating systems: refers to run multiple programs at the same time capacity

  Multi-task under normal circumstances: a program to perform multiple tasks simultaneously . Typically, each task is called a thread.

 

2.3 The difference between processes and threads

1) a thread can belong to only one process, but a process can have multiple threads .

  Multithreading : running a process that is planted in the same time to perform multiple tasks.

2) A thread is a lightweight process, compared with the processes, threads, created to bring the operating system side, the burden of maintenance and management to light, meaning that threads the cost or overhead is relatively small.

3) the thread does not address space, threads contained in the address space of a process . The thread context contains only one stack, a register, a priority, thread text contained in its process text segment, all the resources owned by the process belongs to the thread . All threads share memory resources and processes .

4) the same process multiple threads share code segments (code and constant), the data segment (global variables and static variables), the extended segment (heap memory). But each thread has its own stack segment, the contents of registers, stack segment called running time, used to store all the local variables and temporary variables.

5) parent and child processes using inter-process communication mechanism , through the threads of the same process of reading and writing data to process variables for communication. More convenient communication between threads.

6)

 

State conversion process 2.4

1) status of the process:

  就绪(Ready)状态:线程已处于准备运行的状态,即进程获得了除处理机之外的一切所需资源,一旦得到处理机,即可运行

  执行(Running)状态:进程正在处理机上运行,在单处理机环境下,每一时刻最多只有一个进程处于执行状态

  阻塞(Block)状态:又称等待状态。进程正在等待某一事件而暂停运行。如等待某资源为可用,或等待输入/输出完成。即使处理及空闲,该进程也不能运行。

2)队列:

  就绪队列、等待(阻塞)队列

  处于就绪状态的进程,在调度程序为之分配了处理机之后便开始执行,就绪 -> 执行。

  正在执行的进程如果因为分配他的时间片已经用完,而被剥夺处理机,执行 -> 就绪。

  如果因为某种原因致使当前的进程受阻,使之不能执行,执行 -> 阻塞。

图 进程的物种基本状态及转换

 

 

2.5 进程同步的几种机制

1)同步机制需要遵循的原则

  a. 空闲让进

  b. 忙则等待

  c. 有限等待

  d. 让权等待

2)经典的进程同步问题:生产者-消费者问题;哲学家进餐问题;读者-写者问题(?)

3)进程的同步机制【?】

  管程机制

  信号量机制

  硬件同步机制:

 

2.6 进程的通信方式

  进程通信就是进程间的数据交换,PV操作是低级通信方式,高级通信方式是指以较高效率传递大量数据的通信方式。

  高级通信方式可以分为:共享通信、消息通信、管道通信。这三大类又可分为:管道、命名管道、信号、消息队列、共享内存、信号量以及套接字七小类,如下:

1)管道(pipe):

  管道可以用于具有亲缘关系(指父子进程关系)进程中的通信,允许一个进程和另一个与它有共同祖先的进程之间通信。是一种半双工的通信方式,数据只能单向流动

2)命名管道(named pipe):

  命名管道克服了管道没有名字的限制,因此它除了具有管道所具有的功能以外,还允许无亲缘关系进程间的通信,同样也是半双工的通信方式。

3)信号(signal):

  比较复杂,用于通知接受进程有某种事件发生,除了用于进程间通信外,进程还可以发送信号给进程本身

4)消息(message)队列:

  消息队列是由消息的链表,存放在内核中并由消息队列标识符标识。它克服了信号传递信息少、管道只能承载无格式字节流以及缓冲区大小受限等缺点。

5)共享内存:

  共享内存就是映射一段能被其他进程所访问的内存,这段共享内存由一个进程创建,但多个进程都可以访问。使得多个进程可以访问同一块内存空间,是最快的可用IPC形式,也是针对其他进程间通信方式运行效率低而专门设计的。

6)信号量(semaphore):

  信号量是一个计数器,可以用来控制多个进程对共享资源的访问,常作为一种锁机制,防止某进程正在访问共享资源时,其他进程也访问该资源。主要作为进程间以及同一进程不同线程之间的同步手段。

7)套接字(socket):

  更为一般的进程间通信机制,可用于不同机器之间的进程间通信。

 

2.7 线程同步的方式

1)临界区:

  通过对多线程的串行化来访问公共资源或者一段代码,速度快,适合控制数据访问

2)互斥量:

  采用互斥对象机制,只有拥有互斥对象的线程才有访问公共资源的权限,因为互斥对象只有一个,所以可以保证公共资源不会同时被多个线程访问

3)信号量:

  允许多个线程同一时刻访问同一资源,但是需要限制同一时刻访问此资源的最大线程数目

4)事件(信号):

  通过通知操作的方式来保持多线程的同步,还可以方便的实现多线程的优先级比较的操作

 

Guess you like

Origin www.cnblogs.com/RebeccaG/p/11692514.html