Processes and Threads
- Concurrency and parallelism
Parallelism is where multiple events occur at the same time, and concurrency occurs during the same interval.
- Basic features of the operating system
并发
Program Concurrency execution
共享
Two ways of mutually exclusive sharing and simultaneous access
虚拟
Time Division Multiplexing Technology and Space Division multiplexing technology
异步
Process asynchronous execution, stop and go move forward, time slice
- What is a process?
A program is an ordered set of instructions and data, and a process is a process entity (program segment, data segment, PCB) that executes on the processing machine. A process is an independent unit of system resource allocation and scheduling.
The process is introduced for concurrent execution of programs to improve resource utilization and system throughput.
- What is a thread?
Threads are the basic unit of Independent dispatch, independent operation, and Dispatch. Threads are lightweight processes, threads only have a small amount of resources (TCB, etc.), do not own system resources, and are multi-threaded to share the resources of the process.
Threading is introduced to reduce the space-time overhead of concurrent execution of programs (primarily in creation, revocation, and process switching), making the OS more concurrent.
- The characteristics of the process (the difference from the program)
动态性
A process is a process of execution, which is created, dispatched, executed, revoked, and dies out. The program is static, and if the PCB is not built for it, the program is meaningless.
并发性
Multiple process entities are in memory and can run concurrently over a period of time. Programs that do not have a PCB set up cannot be executed concurrently.
独立性
Process entities can run independently, acquire resources independently, and accept schedules independently. Programs that do not have a PCB set up cannot run independently.
异步性
Processes are run independently and asynchronously, so the program can execute concurrently, and to ensure reproducible results, you need to configure the process synchronization mechanism.
- Status of the process
就绪(Ready)
The process has acquired the necessary resources other than the CPU to be queued by policy
执行(Running)
Process gets CPU, program executes
阻塞(Block)
The process is not able to continue due to events such as I/O requests, resulting in blocking, which requires scheduling, joining the blocking process to the blocking queue, and assigning the processor to the process in the ready queue
创建
Process request PCB, initialize PCB, processor allocate resources for process, finally transfer process to ready state and join ready queue
终止
process during execution due to normal or abnormal need to end, the OS after processing the PCB clear 0 and the PCB space return system.
- Process synchronization Mode
- Hardware synchronization mode, such as off interrupt, swap instruction, test-and-set instruction
- Semaphore mechanism
- Pipe process mechanism
- Classic Process Sync Issues
Producer-Consumer issues
Operating system 01_ processes and threads