Operating system (1)-process management

1. What is an operating system

  • The operating system is a program that manages computer software and hardware resources and is the cornerstone of a computer. The operating system is essentially a software program that runs on the computer and is used to manage software and hardware resources.
  • The operating system shields the complexity of the hardware, so that users only need to pay attention to the software level, which is the interface between the user and the computer hardware
  • The kernel of the operating system is the core part of the operating system, responsible for the system's memory management, hardware management, file management and application management

Two, system call

Before talking about system calls, we must first talk about user mode and core mode. The difference between user mode and core mode is actually the different privilege level.

  • 用户态: The process running in user mode can directly read the data of the user process, only part of the resources can be read
  • 核心态: System processes running in the core state can access almost all resources without restriction

The reason for the need for user mode and core mode is the need to restrict the access capabilities between different programs. If all programs can access the underlying operating system resources, it will not be messy, so the purpose of classifying is to protect the operating system. But in some special cases, programs running in user mode really need to access the core mode, what should I do?

At this time, you need to use system calls, that is to say, for programs running in user mode, all resources related to the system mode level must be applied to the operating system through system calls, and the operating system will complete it on its behalf.

Third, the process? Thread?

Questions about processes and threads can be answered from the perspective of JVM. For example, in JVM memory division, metaspace and heap are shared by threads, while virtual machine stacks, local method stacks, and program counters are private to threads, while running The entire java program is a process. From this point of view, a process can have multiple threads, or it can be combined with specific examples, such as the GC background thread of the java program, etc.

Four, what are the status of the process

The life cycle state of a process is very similar to that of a thread, and can be roughly divided into five states:

  • 创建态: Refers to the state in which the process is being created
  • 就绪态: Refers to the process has been created, if the processor schedule is obtained, the process will be changed from the ready state to the running state
  • 运行态: Refers to the process that has obtained the scheduling of the CPU processor and is in a running state
  • 堵塞态: Refers to the pause state where the process needs to wait for a certain resource, which may be printer resources, IO resources, etc.
  • 结束态: Refers to the end of the process and disappears from the system

5. How to communicate between processes?

There are about 7 ways to communicate between processes:

  • 管道/匿名管道: Used for communication between parent-child processes or sibling processes that have a relationship
  • 有名管道: Anonymous pipes have no names, so they can only be used for parent-child processes or sibling processes. In order to overcome this shortcoming, a well-known pipe is introduced. The well-known pipe follows first-in first-out, which can realize communication between any two pipes. The well-known pipe is based on disk files. Way of storage
  • 信号: Signal is a more complex mechanism that can be used to notify the process that an event has occurred
  • 消息队列: The message queue is a linked list of messages, which has a specific format and is stored in memory. Different from the well-known pipes, the message queue is placed in memory, and the message queue will only be deleted when the kernel is restarted.
  • 信号量: The semaphore is a counter, which solves the access to shared data by multiple processes. The main purpose is the synchronization problem between processes
  • 共享内存: Allows multiple processes to access the same shared memory, and different processes can see other processes' updates to the data in the shared memory, but this method requires some mechanism to ensure such as mutual exclusion locks and semaphores
  • 套接字: Mainly used for communication between the client and server in the network through the network

Six, the way of synchronization between processes

  • 互斥量: Equivalent to Synchronized in java, only objects with mutually exclusive resources can access public resources
  • 信号量: Allow multiple processes to access the same resource, but need to control the maximum number of processes that access this resource at the same time
  • 事件: By means of notification operations to ensure the synchronization of multi-threads, you can also easily achieve priority comparison between multi-threads

Seven, process scheduling algorithm

  • 先来先服务: Select a process that enters the queue first from the ready queue to allocate resources. First-come-first-served algorithm scheduling is good for long jobs, but not good for short jobs. If short jobs are queued behind a large number of long jobs, it will cause performance degradation
  • 短作业优先: Select a process with the shortest estimated running time from the ready queue to allocate resources. This algorithm is not good for long jobs and does not consider the urgency of the job
  • 时间片轮转调度算法: Assign a time slice to each process, and send an interrupt request when the time slice runs out
  • 多级反馈队列算法: First-come, first-served is not good for short jobs, and short jobs are bad for long jobs. The multi-level feedback queue algorithm combines the above advantages. The multi-level feedback queue priority algorithm needs to set up multiple ready queues, and set up multiple ready queues for each The ready queue sets a priority. The queue with high priority has less time slices. When a new entry enters the memory, it is first placed at the end of the first queue. Only when the first queue is free, the scheduler will schedule the second queue. Process running
  • 优先级调度: Assign a priority to each process. The algorithm of the priority is (waiting time + required service time) / required service time, and dispatching resource allocation according to priority

Guess you like

Origin blog.csdn.net/weixin_44706647/article/details/115278301