The process management of Linux learning Path

Source: Internet
Author: User

What is a process?

A process is a process that loads a binary file into an individual that is formed in memory.

In our Linux system, the system only recognizes binary files, so if a system wants to run normally, it must start some binaries to form a process that performs the corresponding tasks in the same way as those processes.


We often hear the so-called procedure, so what is the relationship between the procedure and the process?

Just said the process was formed by loading binary files into memory. And the binaries are the programs.

You can understand this:

The program is a real file and is stored on disk.

A process is a logical concept in which processes are present in memory, so when the machine restarts, the processes are destroyed. And the program does not, because they always exist on the disk.



We know that in our system, we can run multiple programs at the same time, which will result in multiple processes, which will eventually be given to CPU processing, but we have only one CPU, so how do these CPUs handle these processes?

The process has just been said to be in memory. And memory is a piece of address space, so our process occupies an address space in memory for process data. The processes that will be executed are placed in the CPU's executable queue, and the CPU is processed on a per-processor basis. And the kernel allocates a period of time for each of these processes, so that the CPU can effectively process each process, avoiding the CPU's long-time consumption of processing a process.

Process is a process state, the process has a total of 5 states:

1. Task_running: A process in this state is being executed by the CPU or will be executed by the CPU

2, task_interruptible: Called the sleep state can be interrupted. Processes in this state sleep until other conditions

Or the event is completed before it is processed by the CPU. Or when a process has been processed by the CPU, and the kernel is assigned to handle these

The process is too long, and these processes are also in a sleep state. While the process is asleep, the CPU can handle other processes.

3, Task_uniterruptible: Non-interrupted sleep state. Processes that are in this state are non-interruptible, so the incoming

Process waits for other signals to be accepted, so the CPU is waiting.

4, task_stopped,task_traced: Stop or track the status.

When the process receives a sigstop signal, the process is in a stopped state

When a process is manipulated by a process that he is monitoring or tracking, the process is in the task_traced state

5, Task_dead,task_zombie, zombie Status: After the process in this state is completed, does not release the occupied

Memory space, resulting in a smaller amount of physical memory.

So how do you see how the process is used?

You can use the PS command to view

However, PS can only statically view the use of the process, that is, the PS command can only show a certain moment of process usage. Can not dynamically display the use of the process, in order to display the process information dynamically, use the top command to view.

Syntax format: PS [option]

wherein the PS command is divided into BSD style and SYSV style

The BSD style options are:

A: Display therefore terminal-related processes

U: Show the owner of this process

x: Show processes unrelated to the terminal

L: Long format to display

Commonly used with PS aux

For example:

650) this.width=650; "title=" 1.png "src=" Http://s3.51cto.com/wyfs02/M01/3F/85/wKiom1PKb9ygPmx_AAC8mtc3-p4396.jpg " alt= "Wkiom1pkb9ygpmx_aac8mtc3-p4396.jpg"/>

Each of these columns represents a field that has the following meanings:

User: Indicates who is running the process

PID: The ID number of the process that is used to identify the

%cpu: Percentage of CPU resources that the process is using

%MEM: The percentage of physical memory that the process uses off

VSZ: Indicates the amount of virtual memory space used by the process

RSS: Indicates the size of the resident memory space, which is the fixed memory size that the process occupies, and the space cannot be exchanged.

TTY: Indicates which terminal the process is running under

STAT: Indicates the state of the process

Start: Indicates the time elapsed for the process to start until now

Time: Indicates when the process actually uses the CPU to run

Command: Indicates what the actual instructions for executing the process are

The SysV style options are:

-E: Displays all processes as-a

-L: Displayed in long format to show your bash-related processes

-F: Extra full format, which shows more columns

-F: Similar to-F, shows fewer columns

650) this.width=650; "title=" 2.png "src=" Http://s3.51cto.com/wyfs02/M01/3F/85/wKiom1PKdVPCbjxyAAFd-YGL8xo180.jpg " alt= "Wkiom1pkdvpcbjxyaafd-ygl8xo180.jpg"/>

Where these fields are meant to be:

F: Indicates the flag of this process, indicating the summary permissions of the process, common numbers are:

4: The permission for the process is root

1: Indicates that the child process is only replicating (fork) and not actually executing (EXEC)

S: Indicates the status of the process, where:

R: Indicates that the process is in a running state

S: Indicates an interruptible sleep state

D: Indicates a non-disruptive sleep state

T: Indicates that the process is in a stopped state

Z: Indicates that the process is in zombie state and that the content space occupied by the process cannot be removed

PID: ID number of the process

PPID: The process's parent ID number

C: Indicates CPU usage, in percent

PRI: Indicates the priority of the process, the smaller the value, the higher the CPU is processed

The Ni:nice value, which is a nice value that can be used to adjust the priority of the process

ADDR: Represents the address range of the process in memory, which displays '-' when the process is in the running state

SZ: Indicates the amount of memory used by the process

Wchan: Indicates whether the process is working, '-' indicates that the process is running

RSS: The size of the resident memory space, which cannot be swapped out

Stime: The time it takes for the process to start.

TTY: Indicates which terminal the process is running under

Time: Indicates when the process is actually using the CPU

CMD: Indicates what directives are used to execute the process

Ps-o Property 1, Property 2 ...

Used to display the property information specified by the process, the default PS displays only the foreground process, so fewer processes are displayed.

Can usually be used in conjunction with AX options to display the specified property information for all processes

For example: Displays the Pid,comm,ni property information for all processes and displays only 5 rows.

650) this.width=650; "title=" 4.png "src=" Http://s3.51cto.com/wyfs02/M00/3F/86/wKiom1PKgRDgxzmWAACWUYQw3as384.jpg " alt= "Wkiom1pkgrdgxzmwaacwuyqw3as384.jpg"/>

Just said that the PS command can only view the usage information of the process at a certain moment, cannot dynamically display the usage information of the process, and to display the usage information of the process dynamically, use the top command to view

Top: Changes in the dynamic observation process

Syntax format: top [option]

-D #: Specifies the delay time, in seconds, indicating how many seconds each is displayed and the default is 5 seconds

-B: Displayed in batch mode, which is a page after page

-N #: Total number of batches displayed in batch mode

Under the top command, you can also use a number of sub-commands

M: Sort based on the size of the resident memory

P: Sort by CPU percent usage

T: Sort by cumulative time

L: Show average load and start time

T: whether to display process and CPU status related information

M: whether memory-related information is displayed

C: Whether to display full command line information

R: Modify the priority of a process

Q: Exit Top

K: Terminate a process

650) this.width=650; "title=" 39.png "src=" http://s3.51cto.com/wyfs02/M00/3F/88/wKiom1PKhX7QdMiQAAHzxVMTe2E266.jpg "alt=" Wkiom1pkhx7qdmiqaahzxvmte2e266.jpg "/>

The first line shows the following information:

The current system time

The time elapsed from boot to current

How many users are logged into the system?

The average workload value for the process in 1, 5, 15 minutes, the smaller the value, the more idle the system

The second line shows the following information:

How many processes are present on the system?

What are the process states in which these processes are located

The third line shows the following information:

Overall CPU load condition

Line four shows the use of physical memory

Line five shows swap partition usage

In the top section of the screen, only the meaning of one field is described, the other fields are similar to the above field meaning

Time+: Represents the cumulative sum of time that the process actually uses the CPU. (indicates that the process may be reused)

In the above we mentioned the concept of priority and Nice, which are related to the precedence of the process.

We know that the process is formed in memory, and the process is processed by the CPU and must first go into the CPU's executable queue, and then the CPU processes the process in the executable queue one after the other. That is, the processes that are to be processed are all going into the CPU's executable queue, and by default the CPU processes those processes based on the order in which the processes are queued. Therefore, in some cases, some of the more important processes may be later processed, while those that are not important will be treated preferentially. This is obviously not in line with the user's mind. So in order for the CPU to prioritize some processes, it gives each process priority, and the lower the priority value, the more CPU the process is processed.

In the Linux system, the process has a priority range of 0-139.100-139 of them are controlled by the user, and 0-99 are controlled by the kernel.

The new priority of a process is made up of the original priority and nice values.

(new) priority= (old) Priority+nice

Here the nice value range is -20--19

Where the root user can adjust the nice value to -20--19

Normal users can adjust the nice value is 0-19, and ordinary users can only be nice, the higher, cannot be lowered

So change the priority of a process, just change the nice value.

There are 2 ways to change nice values

1. Specify a nice value when starting a process

Syntax format: Nice [-N #] COMMAND

2. Adjust the nice value of the process that has been started

Syntax format: Renice NI PID

For example, to modify the top this process of Nice is 5

650) this.width=650; "title=" 5.png "src=" Http://s3.51cto.com/wyfs02/M02/3F/8B/wKioL1PKlJaynWlAAAHljP1ytbo360.jpg " alt= "Wkiol1pkljaynwlaaahljp1ytbo360.jpg"/>

Management of processes

In fact, the process can be controlled between each other, inter-process related management by sending a signal (Signal) to achieve, different Signal meaning is not the same. The main common signal signal codes and names are:

1:sighup: Allow a process to reread its configuration file without restarting, and let the new configuration information take effect

2:sighint: Use CTRL + C to interrupt a process similar to the command line

9:sigkill: Forcing a process to kill

15:sigterm: Terminates a process (the process exits gracefully to complete termination), which is the default signal

This article from the "Linux Learning Path" blog, declined reprint!

The process management of Linux learning Path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.