Linux Process Management (1)

Source: Internet
Author: User
Tags pkill

Linux Process Management (1)
Process introduction programs and process programs are software designed to complete a task. For example, OpenOffice is a program. What is a process? A process is a running program. A running program may have multiple processes. For example, the WWW server used by self-taught it network is an apache server. When the Administrator starts the service, many people may access it. That is to say, many users request the httpd service at the same time, the apache server will create multiple httpd processes to serve them. Process classification processes are generally divided into three types: interactive processes, batch processing processes, and daemon processes. It is worth mentioning that the daemon process is always active and generally runs in the background. The daemon process is generally started by the system automatically activated by the script or by the super administrator root at startup. For example, in Redhat, we can define the running level of the startup script of the httpd server. This file is located in/etc/init. in the d directory, the file name is httpd,/etc/init. d/httpd is the daemon of the httpd server. When the running level is set to 3 and 5, it starts when the system starts. [Root @ localhost ~] # Chkconfig -- level 35 httpd on process attributes: process ID (PID): A unique value used to differentiate processes; parent process and parent process ID (PPID ); the User ID (UID) and the group (GID) of the startup process. Process status: Running R, sleep S, and zombie Z; priority of process execution; the terminal name that the process is connected to. Process resources are occupied, for example, the occupied resources (memory and CPU usage). Parent and Child processes: the relationship between them is the relationship between management and management, when the parent process is terminated, the child process also terminates. But the child process is terminated, and the parent process is not necessarily terminated. For example, when the httpd server is running, we can kill its child processes. The parent process will not be terminated because of the termination of the child process. In process management, when we find that a process that occupies too many resources or is uncontrollable, we should kill it to protect the stable and secure operation of the system. Process Management manages Linux processes, it is implemented through process management tools, such as ps, kill, pgrep, etc. ps monitoring process tool ps provides us with a one-time View of processes, the query results provided by this tool are not dynamically consecutive. If you want to monitor the process time, you should use the top tool. ps parameters indicate that ps provides many option parameters, the following are commonly used: l long format output; u is used to display processes by user name and start time; j is used to display processes in task format; f is used to display processes in tree format; a: displays all processes of all users (including other users); x displays processes without control terminals; r displays processes in progress; ww avoids detailed parameter truncation; our common options are combination of aux or lax, and the application of parameter f; ps aux or lax output explanation; USER process owner; PID process ID; PPID parent process; % CPU process usage % MEM memory usage percentage; PRI indicates the NICE value of the "executable priority" NI process of the program. The value is large, indicating that the CPU time is less occupied; virtual size of VSZ processes; number of pages in which RSS resides; constant sleep (usually IO) R in which TTY terminal IDSTAT Process status D is running in queue; and sleep in S; T stop or be tracked; W enters memory switching (starting from kernel 2.6 is invalid); X dead processes (never seen before); Z botnets; <process with a higher priority N process with a lower priority L some pages are locked into the memory; s process leader (with sub-processes under it); l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do) + process group in the background; Process resources waiting for WCHAN; START process start time; TIME process CPU consumption TIME; COMMAND name and Parameters Ps application example; instance 1: ps aux is the most commonly used [root @ localhost ~] # Ps-aux | more available | the MPs queue is connected to more and can be viewed by PAGE [root @ localhost ~] # Ps-aux> ps001.txt [root @ localhost ~] # More ps001.txt displays all the processes and outputs them to the ps001.txt file. Then, you can view the instances by page through more. 2. Combine with grep to extract the processes of the specified program;

[root@localhost ~]# ps aux | grep httpdroot      4187  0.0  1.3  24236 10272 ?        Ss   11:55   0:00 /usr/sbin/httpdapache    4189  0.0  0.6  24368  4940 ?        S    11:55   0:00 /usr/sbin/httpdapache    4190  0.0  0.6  24368  4932 ?        S    11:55   0:00 /usr/sbin/httpdapache    4191  0.0  0.6  24368  4932 ?        S    11:55   0:00 /usr/sbin/httpdapache    4192  0.0  0.6  24368  4932 ?        S    11:55   0:00 /usr/sbin/httpdapache    4193  0.0  0.6  24368  4932 ?        S    11:55   0:00 /usr/sbin/httpdapache    4194  0.0  0.6  24368  4932 ?        S    11:55   0:00 /usr/sbin/httpdapache    4195  0.0  0.6  24368  4932 ?        S    11:55   0:00 /usr/sbin/httpdapache    4196  0.0  0.6  24368  4932 ?        S    11:55   0:00 /usr/sbin/httpdroot      4480  0.0  0.0   5160   708 pts/3    R+   12:20   0:00 grep httpd

 

Pgrep is a tool used to query processes by program names. It is generally used to determine whether a program is running. In server configuration and management, this tool is often used, simple and clear; usage: # pgrep parameter option program name common parameter-l list program name and process ID; -o process start ID;-n Process Termination ID; example:
[root@localhost ~]# pgrep -lo httpd4557 httpd[root@localhost ~]# pgrep -ln httpd4566 httpd[root@localhost ~]# pgrep -l httpd4557 httpd4560 httpd4561 httpd4562 httpd4563 httpd4564 httpd4565 httpd4566 httpd[root@localhost ~]# pgrep httpd45574560456145624563456445654566

 

Kill, killall, and pkill are tools used to terminate a process or terminate a running program. They are generally performed through kill, killall, pkill, and xkill. For example, if a program is dead but cannot exit, you should consider using these tools. In addition, in server management, you can use these tools to stop the parent process that does not involve database server programs. Why cannot the parent process of the database server be killed using these tools? The reason is simple. When these tools force terminate the database server, more file fragments will be generated for the database. When the fragmentation reaches a certain level, the database may crash. For example, it is best to close the mysql server according to its normal program, instead of using pkill mysqld or killall mysqld as dangerous actions. Of course, we should use kill to kill database sub-processes that occupy too much resources.

Related Article

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.