A process is an address space in which one or more threads are running and the system resources required by those threads. In general, Linux Systems Share program code and system function libraries between processes, so there is only one copy of the code at any point in memory.
1,ps command
function: The PS command is used primarily to view the status of processes in the system.
Usage: PS [options]
The main options are as follows:
-E Show All processes
-A non-terminal process (BSD style, no crossbar)
-X process related to terminal
-U Initiator
-F Additional Information
-F Display full information
-j displaying a process as a job
-H shows the relationship of the process
-O customize which fields are displayed
Single commands tend to show results that are not ideal, and here we can use multiple options simultaneously.
Example: PS aux command to get all the information about the process for all users on the terminal
USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND
Root 1 0.0 0.1 2064 652? Ss 10:05 0:00 init [3]
where vsz virtual address size
RSS Physical Memory Size
Example: PS ax
PID TTY Stat Time command
1? Ss 0:00 init [3]
In which TTY? Indicates that the terminal is not relevant
Stat (status)
D Non-disruptive sleep
S can interrupt sleep
R is running or can be run
T Stop State
Z Zombie State parent process for child process corpse
When the parent process dies, it finds another parent process for the child process.
X Death Status
W Paging
Change in Status: Stoped--sleep--ready--running
Note: Sleep (can interrupt sleep and non-disruptive sleep)
PID This process ID, the following ppid is the ID of the parent process
In BSD there will also be:
< represents a high-priority process
N Low-priority
+ processes that belong to a foreground group
s a leader process of answering
L Line Cheng
+ Background Run Process Group
Example: Ps-l
[Email protected] ~]# ps-l
F S UID PID PPID C PRI NI ADDR SZ Wchan TTY time CMD
4 S 0 9706 9704 0 0-1166 wait pts/1 00:00:00 bash
4 R 0 9908 9706 0 0-1052-PTS/1 00:00:00 PS
F: Indicates the flag for this process, and 4 indicates that the user is a superuser.
S: Indicates the status of this process (STAT).
PID: The ID of this process, and the following ppid is the ID of the parent process.
Percentage of resources used by C:CPU
The abbreviation for pri:priority (priority).
Ni:nice value
ADDR This is the core feature that indicates that the process is in the memory part, and if it is running the process is generally "-"
SZ: The amount of memory used
Wchan whether the current process is running, or "-" indicates that it is running.
TTY: The terminal location of the logged-in person.
Time: The CPU times that are used off.
The command executed by CMD.
Example: PS Auxw--sort=rss
Sort processes by memory footprint
Example: PS Auxw--sort=%cpu
In the case of system maintenance, if the CPU load suddenly increases without knowing which process is causing the
Other partial PS commands:
Every process on the system using the syntax:
Ps-e
Ps-ef
PS-EF Display PID and ppid information
Ps-ely will show nice value NI and priority pri
Every process on the system using BSD syntax:
PS AX
PS Axu
To print a process tree:
Ps-ejh
PS AXJF equivalent to PS-AFH or AFH show process relationships
To get info about threads
Ps-elf
PS AXMS
To get security Info:
Ps-eo Euser,ruser,suser,fuser,f,comm,label
PS Axz
Ps-em
To see every process running as root (real & effective ID) in user format:
Ps-u root-u Root Custom display format
To see every process with a user-defined format:
Ps-eo Pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
PS Axo Stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
Ps-eopid,tt,user,fname,tmout,f,wchan
Print only the process IDs of SYSLOGD:
Ps-c Syslogd-o pid=
Print only the name of PID 42:
Ps-p 42-o comm=
2,pstree: Show process status tree
Role: The pstree command lists the current processes, as well as their tree structure.
Usage: pstree [options] [Pid|user]
The main options are as follows.
-A: Displays the command and full parameters of the executing program.
-C: Cancel the program with the same name and merge display.
-H: Processes the output and highlights the program being executed.
-L: Displayed in long usage.
-N: Sort by pid size.
-P: Displays PID.
-U: Displays UID information.
-G: Generate a clearer tree using the VT100 terminal encoding display
-u: Displayed using UTF-8 (Unicode) encoding.
It can display the current execution program in a tree-like structure. The Pstree command supports specifying a specific program (PID) or user (user) as the starting point for the display.
3,top: Show Process
Function: The top command is used to display the current process status of the system.
Usage: top [options]
The main options are as follows.
-B: The top is executed in batches, typically paired with data flow redirection, to output batch results as files.
-C: Displays the program and displays complete information about the program, such as its name, path, and so on.
-I: Ignore unused or frozen programs.
-D: The number of seconds after which the whole process is updated, the default is 5 seconds.
-N: Paired with-B, several top output results are required.
-p< Process Number: Specify some PID to observe and detect.
-S: Safe mode.
-U: Specifies the user name.
-V: Displays version information.
-H: Displays help information.
The basic function of the top command and the PS command is the same, showing the current process status of the system. But top is a dynamic display process, that is, you can constantly refresh the current state by pressing the user key.
Example: Top
Top-19:21:34 up 9:15, 3 users, Load average:0.00, 0.00, 0.00
TASKS:80 Total, 1 running, sleeping, 0 stopped, 0 zombie
Cpu (s): 0.0%us, 0.3%sy, 0.0%ni, 99.0%id, 0.7%wa, 0.0%hi, 0.0%si, 0.0%st
mem:515444k Total, 360684k used, 154760k free, 99876k buffers
swap:1048568k Total, 0k used, 1048568k free, 214912k cached
PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
9954 Root 0 2196 992 804 R 0.3 0.2 0:00.05 Top
1 Root 0 2064 620 536 S 0.0 0.1 0:04.26 Init
2 root RT-5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 Root 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
4 root RT-5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
The first line represents the current time, the system startup time, the current number of system logon users, and the average load.
The second line shows all the started, currently running, suspended (sleeping) and useless (Zombie) processes.
The third line shows the current usage of the CPU.
Row four shows the use of physical memory, including total available memory, used memory, free memory, and memory consumed by the buffer.
The five lines show the usage of the swap partition, including the total, used, idle, and swap partitions used for caching.
Line six shows the most items, and the detailed explanations are listed below.
PID (Process ID): Progress flag number, non-0 positive integer.
User: The username of the process owner.
PR: The priority level of the process.
NI: The value of the priority level of the process.
VIRT: The virtual memory value that the process occupies.
RES: The physical memory value that the process occupies.
SHR: Shared memory value used by the process.
STAT: The state of the process, where s indicates hibernation, R is running, Z represents a zombie state, n indicates that the process precedence value is negative
%CPU: The CPU usage that the process consumes.
%MEM: The percentage of physical memory and total memory that the process occupies.
Duration: The total CPU time that is consumed after the process is started.
Command: The start command name of the process startup, and if this line does not appear, the process will have a full command line.
Key commands that you can use during top execution:
?: Displays the key commands you can enter in top.
< space;: Refresh now.
P: Sort the display by CPU usage resources.
T: The process uses the CPU time accumulation (time+) sort.
M: Toggles display memory information.
T: Toggles display of process and CPU status information.
C: Toggle display command name and full command line.
M: Sort the display by memory usage resource.
N: Sort by PID
W: Writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files.
R: Re-determine a value for a PID.
Q: Exit the top command.
The top command is a powerful tool for monitoring systems and is especially important for system administrators. However, its disadvantage is that it consumes a lot of system resources.
Example: Top-c
Display the program and its complete related information
Example: Top-d 3
Set the top command at a time interval of 3 seconds
Example: Top-n 5
Set System task Information Update 5 times after end top command
4,who
Role: This command is primarily used to view the current user situation on-line.
The common parameters of the WHO command are described.
-M, like the role of "Who Am I", displays the name of the user running the program.
-q,--count only shows the number of login accounts and logged-in users of the user, which takes precedence over any other options.
-S ignored. It is primarily intended for compatibility with other versions of the WHO command.
-i,-u,--idle the last time the user has been working on the system since the logon time, which is often said to be "daze" time.
-h,--heading show a row of headings
5,w command
The command is also used to show the user logged on to the system, but unlike who, the W command is more powerful, not only to show who is logged on to the system, but also to show what the users are currently doing, and that the statistics are more detailed and scientific than the WHO command, The W command can be considered an enhanced version of the WHO command.
The corresponding parameters are explained:
-H does not display the caption.
-U ignores the user name when the current process and CPU time are listed. This is primarily the case after the SU command is executed.
-S uses short mode. Logon hours, jcpu, and pcpu times are not displayed.
-F Toggle Displays the from entry, which is the remote host name entry. The default is to not display the remote host name, and of course the system administrator can make some modifications to the source file so that the item is displayed as the default value.
-V Displays version information.
6, other commands used in conjunction
Pgrep-g Root shows all the PID
Pidof CUPSD gets the PID of a process (CUPSD is a process name)
Free-m viewing the use of virtual memory
Kill process Number The default signal is 15
Killall Process Name
Example: Killall httpd
Pkill Singal pattern
7,nice Value and Priority
Static priority: 100-139, can be adjusted
Dynamic priority: 0-99 Digital small priority small (real-time priority)
Manual adjustment, Nice (-20-19) defaults to zero to lower your own priority (normal users)
You can adjust your priorities (root manager) at your discretion.
Nice values are specified directly when you start the process
Nince-n 6 COMMAND
Renice: Adjust its nice value for a process that has already been started
Renice-5 423 (-5 for Nice value, priority, 423 for process number)
8, Operation control (Job)
In practice: Shell end job also ends
After use &: Shell end job does not end
Example: Nohup cp-r/ETC/TMP/ABC &
Shell ends, job does not end
CTRL + Z send job to backstage stoped status
& is also running in the background
FG call to Foreground
Jobs view assignments in the background
FG calls a job with a + number by default, invoking a background job
PS aux | LS View the ID of LS
BG%2 2 is the job number
Kill%2 directly kills job display terminated
Kill-9%2 direct Kill show killed
Original from the "Bit network", reproduced please keep the original link: http://soft.chinabyte.com/os/283/12130783.shtml
on how to view process--ps,pstree,top,w in Linux system, full solution