Linux Process Management-ps,top,pstree,signal,kill,killall Example Demo

Source: Internet
Author: User

PS: Capture the process run at a point in time

[[Email protected] ~]# PS aux  <== observation System all process data [[email protected] ~]# Ps-la  <== is also able to observe the system data [email Protected] ~]# PS AXJF <== together with some process tree state options and Parameters:-a  : All processes are shown with the same utility as-e;-a  : all process not related to terminal;-u
   : Effective user (effective user)-related process; X   : Typically used with the A parameter to list more complete information. Output format planning: L   : A longer, more detailed list of information about the PID; J   : Working format (jobs format)-F  : Make a more complete output.

Ps-l only observe his own bash program

EG1: List the PID and related inquiries that are currently part of your login (only related to your bash)


Use Ps-l to list only the processes associated with your bash, and the data displayed by Ps-l are:

F: Represents the process flag, which describes the summary permissions for this process, and the common numbers are:
If 4 indicates that the permission for this process is root;
A 1 indicates that the child process is only replicating (fork) and not actually running (exec).

S: Represents the status of this process (STAT), the main state is:
R (Running): the process is running;
S (Sleep): The process is currently sleeping (idle), but can be awakened (signal).
D: Sleep state that cannot be awakened, usually this process may be waiting for I/O (ex> print)
T: Stop state (stop), which may be in the work control (background pause) or the traced State;
Z (Zombie): Zombie status, the process has been terminated but cannot be removed to memory.

Uid/pid/ppid: Represents "This process is owned by this UID/process PID number/parent process PID Number of this process"

C: Represents CPU utilization, in percent;

The pri/ni:priority/nice abbreviation, which represents the order in which the process is run by the CPU, the smaller the value, the faster the process is run by the CPU.

Addr/sz/wchan: All memory-related, ADDR is kernel function, indicating which part of the program, if it is a running program, will generally show "-"/SZ represents how much memory the program uses/Wchan indicates whether the program is currently running , similarly, if-indicates that it is running.

TTY: The terminal location of the lander, if the remote login uses the dynamic termination interface (pts/n);

Time: Use off CPU times, note that this process actually spends the CPU running time, not the system time;

CMD: is the abbreviation of command, which causes the order of the triggering process of this process.


PS AUS Observing all processes of the system

EG2: List all currently in-memory processes:


。。。


Ps-l and PS aux display items are not the same! In the PS aux display project, each of the meanings is:

User: Does the process belong to that user account?
PID: The process Identification code for this procedure.
%CPU: The percentage of CPU resources that the process uses off;
%MEM: The percentage of physical memory occupied by the process;
VSZ: The amount of virtual memory that the process uses (Kbytes)
RSS: The amount of fixed memory that the process occupies (Kbytes)
TTY: The process is running on that terminal, if it is not related to the terminal, display?, in addition, TTY1-TTY6 is the user above the lander program, if it is pts/0 and so on, it is represented by the network into the host computer program.
STAT: The current state of the process, showing the same status as the Ps-l S flag (r/s/t/z)
Start: The time at which the process is triggered to start;
Time: The process actually uses the CPU runtime.
Command: What is the actual command for this process?


Ps-la Show all processes in the same way as the output of ps-l



PS AXJF lists programs similar to the process tree display:




Top: Changes in the dynamic Observer program

[[email protected] ~]# Top [-D number] | Top [-BNP] options and Parameters:-D  : The number of seconds to follow can be followed, that is, the entire process screen upgrade seconds. The default is 5 seconds;-B  : Run top in batch mode with more parameters to use! It is      often paired with data flow redirection to export batches of results to a file.  -N: Paired with-B, the meaning is that several top output results are required.  -P: Specify some PID for observation and monitoring. Key commands that can be used during the top run:? : Displays the key commands that can be entered in the top, P: Sort the display using the CPU resource, M: Sort the display using the Memory resource; N: Sort by PID! T: The CPU Time accumulation (time+) used by the Process is sorted. K: give some PID a signal  (signal) R: give some PID a nice value to re-establish. Q: The key to leave the top software.



Top is mainly divided into two pictures, the above screen for the entire system of resource use state, basically a total of six lines, the content of the display is:

First line (top ...) : The information shown in this line is:
The current time, that is, 18:30:00 that project;
The time that has elapsed so far, that is, the project up to 4:17;
The number of users who have logged into the system, that is, the 2 user project;
The system averages the workload at 1, 5, 15 minutes. On behalf of 1, 5, 15 minutes, the system average is responsible for running several programs (work) meaning. The smaller the system, the more idle it is, and the more you need to be aware of the complexity of your system's progress if it is 1.

Second row (Tasks ...) : Shows the total number of processes currently in progress with individual processes in what state (running, sleeping, stopped, zombie). The comparison needs to be noted is the last zombie that value, if not 0! Take a good look at that process and become a zombie, right?

Third line (Cpus ...) : Displays the overall CPU load, which can be used for each project? Inspection. Special attention is WA, that project represents I/O wait, usually your system will be slow is the problem of I/O is relatively large! So it's important to note that this project consumes CPU resources. In addition, if the device is multi-core, you can press the number key "1" to switch to different CPU load rate.

Row four and line fifth: represents the current use of entity memory and virtual memory (MEM/SWAP). Again, it is important to note that the use of swap should be as small as possible! If swap is used a lot, it means that the system's physical memory is not enough!

Line six: This is where the state is displayed when the command is entered in the top program.


To the bottom half of the picture, the resource situation is used for each process. The comparison needs to be noted:

PID: ID of each process!
SER: The user to whom the process belongs;
Pr:priority shorthand, process priority run order, the smaller the sooner it is run;
The abbreviation of Ni:nice, which is related to priority, is also smaller and sooner run;
%cpu:cpu of the use rate;
%MEM: Memory utilization;
Time+:cpu the use of the time accumulation;

Top by default uses CPU usage (%CPU) as the focus of the sort, and if you want to sort by using memory usage, you can press "M" and then press "P" to reply. If you want to leave top then press "Q"


Eg: your own bash PID can be obtained from variable $$, using top to continuously observe this PID



Ptree

[Email protected] ~]# Pstree [-a| U] [-up] options and Parameters:  -A: The connection between each process tree is connected in ASCII bytes;  -U: The connection between each process tree is connected in the bytecode byte. There may be errors under certain terminal interfaces,  -P: And also list the pid;-u for each process  : And also list the account name of each process.
Eg: Lists the dependencies of all process trees on the current system



Eg: simultaneous display of PID and users


Within the brackets () is the PID and the owner of the program! However, since I was using

Root to run this command, so the root program will not show up!


Management of processes

Processes can be controlled from one another! For example, you can shut down, restart the server software, the server software itself is a program, since you can let her shut down or start, of course, you can control the process! So how does the process manage each other? In fact, by giving the process a signal (signal) to tell the process what you want her to do!

So how many signal are there? You can use the kill-l (lowercase l) or the man 7 signal can be queried!


The main signal code and name correspondence and the content is:

Code Name Content
1 SIGHUP Starts the terminated process, allowing the PID to re-read its profile, similar to restarting
2 SIGINT Rather than using keyboard input [ctrl]-c to interrupt a process
9 SIGKILL The representative forces a process to break, and if the process is halfway through, then the unfinished part may have a "half product", similar to vim. Filename.swp.
15 SIGTERM Terminates the process with a normal end process. Because it is normal to terminate, so the subsequent action will be completed by him. However, if the process already has a problem, it is not possible to use the normal method of termination, it is useless to enter this signal.
17 SIGSTOP Rather than using keyboard input [ctrl]-z to pause a process

Kill-signal PID

Kill can help us transfer this signal to a job (%jobnumber) or to a PID (directly entering a number). To re-emphasize is: kill after the direct addition of numbers and add%number case is different! This is important! Because the work control has 1th work, but PID 1th is the "init" this process! How can you turn off init? Shut down INIT and your system will be gone! So remember that percent is specifically used in the work of control Oh!

After understanding this usage, if in the future you want to remove the connection of an inexplicable lander, you can find the relevant program by using PSTREE-P, and then delete the program with kill-9, the line will be kicked off!


killall-signal command name

[[email protected] ~]# killall [-iie] [command name] options and Parameters:-I  : interactive meaning, interactive, if need to delete, will appear prompt bytes to the user;-e  : exact means "command name to follow", but the entire complete command      cannot exceed 15 bytes.  -I: the command name (possibly with parameters) ignores case.
Eg: once asked if each bash process needs to be terminated!



In short, to delete a process, we can use the PID or the command name to start the program, and if you want to delete a service? Oh! The simplest way to do this is to use killall, because he can remove all programs that start with a command name in the system.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux Process Management-ps,top,pstree,signal,kill,killall Example Demo

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.