1 Basic concepts:
process : The entity on which the computer has run the program. The program itself is only a collection of instructions, the process is the real operation of the program. When a user releases a command to run a program, a process is generated.
a process typically has 5 states, the first 3 of which are the basic state of the process. They are: running state; ready state; blocking state; creating state; ending state. where the ready state means that the process obtains everything except the processor, and once it gets the processor it can run. A blocking state is a process that is waiting for an event to pause, waiting for a resource to be available (excluding storage) or waiting for input and output to complete.
The difference between a process and a program: 1. A process is a running activity of a program and its data on a computer, which is a dynamic concept. Processes are made up of programs, data, and process Control blocks (JCB). A program is a set of ordered sets of instructions, which is a static concept. 2, the process is a process of execution of a program, with a certain life cycle, can be permanent, can be long-term preservation. 3. A process can execute one or several programs, a program can also form multiple processes, processes can create processes, but the program does not form a new program. 4. The composition of processes and procedures is different.
Threads : Sometimes referred to as lightweight processes, are the smallest unit of program execution. A standard thread consists of a thread ID, a current instruction pointer (PC), a register, and a stack. threads also have three basic states of readiness, blocking, and running.
A thread is a single sequential control process in a program that runs multiple threads at the same time in a single program to accomplish different tasks, known as multithreading .
The difference between threads and processes : 1. Scheduling, the process is the basic unit of resources, the thread is the basic unit of the Independent dispatch. In the same process, the switch of the thread does not cause the process to switch, which causes the process to switch between threads in different processes. 2. A resource, a process is the basic unit that owns the resource, the thread does not own the resource, but the thread can share the system resources of its subordinate process. 3. Concurrently, a process can execute concurrently, and multiple threads within the same process can execute concurrently. 4. System overhead, when creating and revoking processes, the system allocates or reclaims the resources, the thread switches only to save a small amount of register content, the cost is low, multiple threads within the same process share the process's address space, so synchronization and communication between these threads is easy to implement, even without operating system intervention. 5. Address space and other resources, the address space of the process is independent of each other, sharing process resources with each thread of the same process. 6. Interprocess communication requires an operating system, and threads can communicate directly through the read-write process data segments.
Process communication and process synchronization
Linux inter- thread communication: Mutex (mutex), semaphore, condition variable
Windows interprocess communication: Pipelines, shared memory, message queues, semaphores, sockets.
Windows inter- thread Communication: critical section (Critical), mutex (mutex), Semaphore (semaphore) (Semaphore), event. Note: The difference between a critical section and a mutex: critical section Intelligence is used to synchronize threads within this process, not to synchronize threads in multiple processes. mutexes, semaphores, events can be used to synchronize data across processes, the critical section is non-kernel objects, only in the user too lock operation, fast, the mutex is a kernel object, in the nuclear mentality (need processor participation) run, slow.
Process scheduling algorithm: First come first service algorithm (FCFS), short job first (SJF), priority scheduling algorithm, high corresponding priority algorithm, time slice rotation algorithm, multi-level feedback queue scheduling algorithm.
Deadlock: A deadlock (waiting for each other) of multiple processes due to competing resources that cannot be pushed forward without the use of external forces.
The cause of deadlock: the competition of system resources, the sequence of process advancement is illegal.
The necessary conditions for deadlock generation: mutually exclusive conditions, non-deprivation conditions, request and hold condition, cyclic conditions.
The banker algorithm is famous for the deadlock avoidance algorithm.
I. Process Management