Sons of Thunder chat concurrent programming (002): Process Description

What is the process

The process is defined: means can run and as a basic unit of resource allocation in a separate system, which is composed of a set of machine instructions, data, stack, and other components of the active entity is able to operate independently.
Popular straightforward talk: Process is a program running on the system, the program is run once the process.

View the process

In Windows, open the QQ software program, the system will create a process to be easy and intuitive to see the task bar manager. As shown below:

ps -aux command

In the Linux operating system, ps -aux instruction execution, shown below.

ps -aux command

Process features

Dynamics: the essence of the process is the execution of a program in a multiprogramming system, the process is dynamically generated, dynamic extinction. In PHP the WEB program, are dynamically generated each time a user requests a process php-fpm, and after the end of the dynamic die. Dynamic process can be viewed through the top order.

Concurrency: any process can be executed concurrently along with other processes. Process and thread-like have concurrency, single-core CPU, progress in dealing with multi-tasking, and also take turns using the same thread resources.
Independence: the process is a basic unit can operate independently, but also the system of allocation of resources and scheduling of independent units. On Windows systems, open multiple applications, each application consumes resources vary.
Asynchronous: As mutual restraint between processes, so that the process has intermittent execution of that process by independent, unpredictable pace to move forward. It's like we are running on the Windows operating system in both browsers, and can run at the same time a message is received QQ, independent and not dependent on each other between them independently of each other, each program has kept running.
Structure: the process control block of three parts by a program, data and processes. The configuration characteristic can be complicated, in the progress of the PCB sections detail.

ps -aux command

Process life cycle

(1) → Ready execution
process in the ready state, when the process scheduler recomputed processor, the process then transitions from the ready state to the execution state.

(2) → Ready execution
process executed in the state in which its execution, because it is assigned a time slice has been exhausted or higher priority preemption process had to give up the processor, then the process of transition from the execution state into a ready state.

(3) → blocking execution
when the process is being executed due to the occurrence of an event temporarily unable to continue, then give up the processor is in a suspended state, namely the implementation of the process is blocked, this suspended state called the blocking state.
Process it is blocked arranged in a queue, called a blocking queue, some systems, depending on the cause of the blockage and the process has been blocked state arranged in multiple queues.

(4) → Ready blocking
process is blocked, and if it waits for the event has occurred, then the process from the blocking state to ready state.

(5) Run → terminates
program execution is completed, revocation terminates.

For example:
to run Java programs through java jar command that creates a process, while the Ready state. User requests access to applications via Http, CPU scheduling to this process. Real-time process returns the results to the user, and enter the ready. When the program processing takes a long time, that process is in the clogged state (CPU, but not blocked, would like to schedule time slots to another process). And other procedures processing is completed, and enter the ready state continues to wait for user requests. Assuming that the program causes the program to crash in the course of treatment, severe cases it is possible to terminate the process.

These are the three most classic and most basic process status (ready, perform, jam), but now the operating system will need to be redesigned according to the new state.

ps -aux command

Operating status: Merge is ready to run state and the state, it indicates that the process is running or ready to run.
Interruptible sleep (light sleep): the process is sleeping (blocked), waiting for the arrival of a wake-up resources can be interrupted by other processes wake-up signal or clock into the run queue.
Uninterruptible sleep (deep sleep state): and its shallow sleep basically similar, but one thing is not another process clock signal or interrupt.
Pause state: the process to suspend the acceptance of some kind of processing. As it is being debugged process in this state.
Zombie state: the process has been completed but not released PCB.

top command

In the Linux system, that process of state and other information can be entered using the top command to view information:
PID: Process ID
the USER: Process owners of
PR: priority of the process
NI: nice value, a negative value indicates a high priority, positive value indicates a low priority
VIRT: process the virtual memory size
RES: process uses the size of physical memory
SHR: process uses shared memory size
S: state of the process, D = sleep, R = running state, S = sleep, T = stopped state, Z = zombie
% CPU: the process takes a percentage of CPU
% MEM: process physical memory occupied percentage
tIME +: the process takes a total duration of the CPU
cOMMAND: process uses the command line using the top -c view detailed Command Line

At last

Why learning process, namely because of the processor CPU management can be attributed to the management of the process. Further, to control the process, you will be able to maximize the use of CPU resources, increase process efficiency.

Search and concern micro-channel public number: iamleiyongjun; every week [] progressive approach to concurrent programming tutorials to share, develop middleware is no longer a dream!

Guess you like

Origin www.cnblogs.com/guanqi/p/11768550.html