Linux Process Management (2)
Connect to [linux Process Management (1)] kill, killall, and pkill tools used to terminate a process or terminate a running program, generally, kill, killall, pkill, and xkill are used. 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. The Application of kill is used together with ps or pgrep commands. Usage of kill: kill [signal code] process ID. Note: The signal code can be omitted; our commonly used signal code is-9, indicating forced termination. For example: [root @ localhost ~] # Ps auxf | grep httpdroot 4939 0.0 0.0 5160 708 pts/3 S + \ _ grep httpdroot 4830 0.1 1.3 24232 10272? Ss/usr/sbin/httpdapache 4833 0.0 0.6 24364? S \ _/usr/sbin/httpdapache 4834 0.0 0.6 24364 4928? S \ _/usr/sbin/httpdapache 4835 0.0 0.6 24364 4928? S \ _/usr/sbin/httpdapache 4836 0.0 0.6 24364 4928? S \ _/usr/sbin/httpdapache 4837 0.0 0.6 24364 4928? S \ _/usr/sbin/httpdapache 4838 0.0 0.6 24364 4928? S \ _/usr/sbin/httpdapache 4839 0.0 0.6 24364 4928? S \ _/usr/sbin/httpdapache 4840 0.0 0.6 24364 4928? S \ _/usr/sbin/httpd Let's view the httpd server process; you can also use pgrep-l httpd to view it; let's look at the second column in the above example, is the process PID column, where 4830 is the parent process of the httpd server, and the process from 4833-4840 is its 4830 sub-process; if we kill the parent process 4830, the sub-process under it will also die; [root @ localhost ~] # Kill 4840 Note: kill the 4840 process. [root @ localhost ~] # Ps-auxf | grep httpd Note: What are the results? Is the httpd server still running? [Root @ localhost ~] # Kill 4830 Note: kill the httpd parent process. [root @ localhost ~] # Ps-aux | grep httpd Note: Check whether other httpd sub-processes exist and whether the httpd server is still running? For zombie processes, you can use kill-9 to force termination and exit. For example, a program has completely died. If kill does not require signal strength, there is no way to exit, the best way is to add signal strength-9, followed by killing the parent process; for example, [root @ localhost ~] # Ps aux | grep gaimbeinan 5031 9.0 2.3 104996 17484? S gaimroot 5036 0.0 0.0 5160 724 pts/3 S + grep gaim or [root @ localhost ~] # Pgrep-l gaim5031 gaim [root @ localhost ~] # Kill-9 5031 killall usage: killall is a running program name. killall is also used with ps or pgrep for convenience. You can use ps or pgrep to check which programs are running. Example: [root @ localhost beinan] # pgrep-l gaim2979 gaim [root @ localhost beinan] # killall gaimpkill pkill is similar to the killall application method, and it also directly kills running programs; if you want to kill a single process, use kill to kill it. Application Method: # pkill example of running program name: [root @ localhost beinan] # pgrep-l gaim2979 gaim [root @ localhost beinan] # pkill gaimtop tool for monitoring system tasks: compared with ps, top is a tool for dynamically monitoring system tasks, and the output result of top is continuous. top call method: top selection parameter:-B runs in batch mode, but cannot accept command line input;-c shows command line, not just command name;-d N shows the interval of two refresh times, such as-d 5, indicates that the interval between two refreshes is 5 seconds.-I indicates that idle or zombie processes are prohibited.-n indicates that NUM indicates the number of updates and then exits. For example,-n 5 indicates that the top five data updates will exit;-p PID only monitors the ID of the specified process; PID is a value;-q will be refreshed without any delay; run in-s safe mode, disable some valid mutual commands, and output the total CPU time of each process in-S cumulative mode, including dead sub-processes; Interactive command key bit: space is updated immediately; c switch to the command name display, or display the entire command (including parameters); f, F add display fields, or delete display fields; h ,? Displays help information about the security mode and accumulation mode. k indicates the ID of the process to be killed, which is used to kill the process (the message number is 15). I disable idle and zombie processes; l average load and normal running time for switching to the display mode; m is switched to the memory information and sorted by memory usage; n is the number of processes displayed, for example, input 3, three processes are displayed on the screen; o and O change the order of the display fields; r applies renice to a process, prompting you to enter the PID and renice values; s changes the interval between two refreshes, in seconds; t switches to display the process and CPU status information; A is sorted by the process life size, and the latest process is shown at the beginning; M is sorted by memory usage, from large to small; N is sorted by process ID size, from large to small; P is sorted by CPU usage, and switched from large to small to the cumulative time mode; T sorts tasks by time/accumulation time; W writes the current configuration ~ /. Toprc; top Application Example: [root @ localhost ~] # Top then, according to the interaction commands mentioned above, you can try it out. For example, by M, you can sort by memory usage. Of course, you can upload the top output to a file; [root @ localhost ~] # Top> mytop.txt then we can view the mytop file to slowly analyze the system process status;