operating system

1. As the manager of computer system resources, the operating system has the following capabilities
1) Processor management
    In the multiprogramming environment, the allocation and operation of the processor are based on the process (or thread) as the basic unit, so the management of the processor can be attributed to the management of the process. Concurrency runs multiple processes in the computer at the same time. Therefore, when the process is created, when it is cancelled, how to manage it, how to avoid conflicts, and reasonable sharing are the most important tasks of process management. The main functions of process management are: process control, process synchronization, process communication, deadlock processing, processor scheduling, etc.

2) Memory management
    The purpose of memory management is to provide a good environment for the operation of multi-program programs, to facilitate the use of users and to improve the utilization of memory. It mainly includes functions such as memory allocation, address mapping, memory protection and sharing, and memory expansion.

3) File management
    The information in the computer exists in the form of files, and the part of the operating system responsible for file management is called the file system. File management includes file storage space management, directory management, and file read-write management and protection.

4) Device management
    The main task of device management is to complete the user's I/O request, facilitate the user to use various devices, and improve the utilization of the device, mainly including buffer management, device allocation, device processing and virtual devices and other functions.

Second, the difference and connection between parallelism and concurrency

    Parallelism and concurrency are two concepts that are both similar and different. Parallelism is when two or more events occur at the same time. Concurrency is when two or more events occur within the same time interval.

    In a multiprogramming environment, concurrency means that in a period of time, there are multiple programs running at the same time on a macro . It can only be performed alternately in time-sharing. If there are multiple processors in the computer system, the programs that can be executed concurrently are distributed to the multiple processors to realize parallel execution, that is, each processor is used to process a program that can be executed concurrently.

The characteristics of the process

    A process is caused by the concurrent execution of multiple programs, and it is two completely different concepts from a program. The basic characteristics of a process are compared with the sequential execution of a single program, and it is also a basic requirement for process management.
  1. Dynamic: A process is an execution of a program. It has processes such as creation, activity, suspension, and termination. It has a certain life cycle and is dynamically generated, changed and died. Dynamics are the most fundamental characteristics of a process.
  2. 并发性:指多个进程实体,同存于内存中,能在一段时间内同时运行,并发性是进程的重要特征,同时也是操作系统的重要特征。引入进程的目的就是为了使程序能与其他进程的程序并发执行,以提高资源利用率。
  3. 独立性:指进程实体是一个能独立运行、独立获得资源和独立接受调度的基本单位。凡未建立PCB的程序都不能作为一个独立的单位参与运行。
  4. 异步性:由于进程的相互制约,使进程具有执行的间断性,即进程按各自独立的、 不可预知的速度向前推进。异步性会导致执行结果的不可再现性,为此,在操作系统中必须配置相应的进程同步机制。
  5. 结构性:每个进程都配置一个PCB对其进行描述。从结构上看,进程实体是由程序段、数据段和进程控制段三部分组成的。

四、进程的状态
  1. 运行状态:进程正在处理机上运行。在单处理机环境下,每一时刻最多只有一个进程处于运行状态。
  2. 就绪状态:进程已处于准备运行的状态,即进程获得了除处理机之外的一切所需资源,一旦得到处理机即可运行。
  3. 阻塞状态,又称等待状态:进程正在等待某一事件而暂停运行,如等待某资源为可用(不包括处理机)或等待输入/输出完成。即使处理机空闲,该进程也不能运行。
  4. 创建状态:进程正在被创建,尚未转到就绪状态。创建进程通常需要多个步骤:首先申请一个空白的PCB,并向PCB中填写一些控制和管理进程的信息;然后由系统为该进程分配运行时所必需的资源;最后把该进程转入到就绪状态。
  5. 结束状态:进程正从系统中消失,这可能是进程正常结束或其他原因中断退出运行。当进程需要结束运行时,系统首先必须置该进程为结束状态,然后再进一步处理资源释放和回收等工作。
   
  就绪状态 -> 运行状态:处于就绪状态的进程被调度后,获得处理机资源(分派处理机时间片),于是进程由就绪状态转换为运行状态。

  运行状态 -> 就绪状态:处于运行状态的进程在时间片用完后,不得不让出处理机,从而进程由运行状态转换为就绪状态。此外,在可剥夺的操作系统中,当有更高优先级的进程就绪时,调度程度将正执行的进程转换为就绪状态,让更高优先级的进程执行。

  运行状态 -> 阻塞状态:当进程请求某一资源(如外设)的使用和分配或等待某一事件的发生(如I/O操作的完成)时,它就从运行状态转换为阻塞状态。进程以系统调用的形式请求操作系统提供服务,这是一种特殊的、由运行用户态程序调用操作系统内核过程的形式。

  阻塞状态 -> 就绪状态:当进程等待的事件到来时,如I/O操作结束或中断结束时,中断处理程序必须把相应进程的状态由阻塞状态转换为就绪状态。

五、线程与进程的比较
  • 1)调度。在传统的操作系统中,拥有资源和独立调度的基本单位都是进程。在引入线程的操作系统中,线程是独立调度的基本单位,进程是资源拥有的基本单位。在同一进程中,线程的切换不会引起进程切换。在不同进程中进行线程切换,如从一个进程内的线程切换到另一个进程中的线程时,会引起进程切换。
  • 2)拥有资源。不论是传统操作系统还是设有线程的操作系统,进程都是拥有资源的基本单位,而线程不拥有系统资源(也有一点必不可少的资源),但线程可以访问其隶属进程的系统资源。
  • 3)并发性。在引入线程的操作系统中,不仅进程之间可以并发执行,而且多个线程之间也可以并发执行,从而使操作系统具有更好的并发性,提高了系统的吞吐量。
  • 4)系统开销。由于创建或撤销进程时,系统都要为之分配或回收资源,如内存空间、 I/O设备等,因此操作系统所付出的开销远大于创建或撤销线程时的开销。类似地,在进行进程切换时,涉及当前执行进程CPU环境的保存及新调度到进程CPU环境的设置,而线程切换时只需保存和设置少量寄存器内容,开销很小。此外,由于同一进程内的多个线程共享进程的地址空间,因此,这些线程之间的同步与通信非常容易实现,甚至无需操作系统的干预。
  • 5) 地址空间和其他资源(如打开的文件):进程的地址空间之间互相独立,同一进程的各线程间共享进程的资源,某进程内的线程对于其他进程不可见。
  • 6) 通信方面:进程间通信(IPC)需要进程同步和互斥手段的辅助,以保证数据的一致性,而线程间可以直接读/写进程数据段(如全局变量)来进行通信。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325660921&siteId=291194637