1. What is a process
? A process is a running instance of an executable program that has been started, and the process has the following components:
? (1) The address space of the allocated memory;
? (2) Security attributes, including ownership credentials and privileges;
? (3) One or more execution threads of the program code;
? (4) Process status
Program: Binary file, static/bin/date,/usr/sbin/httpd,/usr/sbin/sshd,/usr/local/nginx/sbin/ngix
Process: Is the state of the program running, dynamic, life cycle and running state
2. The life cycle of the process
? The parent process replicates its own address space (fork) to create a new (child) process structure. Each new process assigns a unique process ID (PID) that satisfies the need for tracking security. The PID and parent process IDs (PPID) are elements of the child process environment, and any process can create child processes, all of which are descendants of the first system process.
? The child process inherits the security identity of the parent process, past and current file descriptors, port and resource privileges, environment variables, and program code. The child process may then exec its own program code.
? Typically, the parent process is in a sleep (sleeping) state while the child process is running. When a child process completes (exit) a signal request, at exit, the child process has closed or discarded its resource environment, the remainder is called Zombie Zombie. The parent process wakes up when the child process exits, cleans up the remaining structure, and then resumes execution of its own program code.
? In a multitasking operating system, each CPU (CORE) can handle only one process at a point in time. As the process runs, its requirements for CPU time and resource allocation change, assigning a state to a process that changes as the environment requires it.
3. Review process processes
? (1) Static viewing process (PS)
[[email protected]~] #ps aux |less
USER pid%cpu%mem VSZ RSS TTY STAT START time COMMAND
Root 1 0.0 128096 6708? Ss 16:20 0:01/usr/lib/systemd/systemd
——————————————————————————————————————————————————
User: Users running the process
PID: Process ID
%CPU:CPU occupancy Rate
%MEM: Memory usage
VSZ: Consuming virtual memory
RSS: Consuming Real memory
TTY: Process run terminal//can open vim query to terminal name
STAT: Process Status man PS (/state)
——————————————————————————————————————————————————
R Run
S can interrupt sleeping sleep (in hibernation, blocked, waiting for a condition to form or receive a signal)
D Non-disruptive sleep (received signal does not wake up and not run, process must wait until there is an interruption)
T Stop the process
Z Zombie Process
X dead Process
? (2) Process sequencing
? Example 1: In descending order of CPU%
? [[email protected]~] #ps aux--sort%cpu |less//--sort Sort, ascending (small to large)
? Example 2: In ascending order of CPU percentage
? [[email protected]~] #ps aux--sort-%cpu |less//-%cpu Descending
? Example 3: Sort in ascending memory
? [email protected]~] #ps aux--sort rss|less
? Example 4: In descending order of resident memory
? [[email protected]~] #ps aux--sort-rss|less
? (3) Parent-child relationship of the process 1
? Install a process watch, parent-child process, and state. Father SS and son s
? [[email protected]~]$ sudo yum-y install httpd//Installation website program.]
? [[email protected]~]$ sudo systemctl start httpd//Start Web site
?] [[email protected] ~]$ sudo systemctl stop firewalld//Turn off firewall
? [[email protected]~]# PS aux |grep httpd//View website program.
? root 9279 0.0 0.0 4264 672 PTS/1 s+ 14:37 0:00 _ grep httpd
? Root 8310 0.0 0.1 10092 2912? Ss 14:19 0:00/usr/sbin/httpd
? Apache 8311 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? Apache 8312 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? Apache 8313 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? Apache 8314 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? Apache 8315 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? Apache 8316 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? Apache 8318 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? Apache 8319 0.0 0.0 10092 2060? S 14:19 0:00 _/usr/sbin/httpd
? (4) Parent-child relationship of the process 2
? View the parent-child relationship for the process. Please observe the PID and Ppid
? [[Email protected]~]# ps-ef
? UID PID PPID C stime TTY time CMD
? Root 1 0 0 January 22? 00:00:07/usr/lib/systemd/systemd
? Root 2 0 0 January 22? 00:00:00 [Kthreadd]
? Root 3 2 0 January 22? 00:00:06 [ksoftirqd/0]
? (5) Custom display fields
? Custom display Fields--------------------------------
? [[Email protected] ~]# PS Axo user,pid,ppid,%mem,command//XO specified column display
? [[Email protected] ~]# PS Axo user,pid,ppid,%mem,command |grep httpd
? Root 8310 1 0.1/usr/sbin/httpd
? Apache 8311 8310 0.0/usr/sbin/httpd
? Apache 8312 8310 0.0/usr/sbin/httpd
? Apache 8313 8310 0.0/usr/sbin/httpd
? Apache 8314 8310 0.0/usr/sbin/httpd
? Apache 8315 8310 0.0/usr/sbin/httpd
? Apache 8316 8310 0.0/usr/sbin/httpd
? Apache 8318 8310 0.0/usr/sbin/httpd
? Apache 8319 8310 0.0/usr/sbin/httpd
? Root 9236 6798 0.0 grep httpd
——————————————————————————————————————————————————
? [Email protected]~]# PS Axo user,pid,ppid,%mem,%cpu,command--sort-%cpu |less
? For some programs, display some columns, and then sort them. Simple and straightforward
? (6) View PID of the specified process, four methods
? The first kind. Cat
? [Email protected] ~]$ Cat/run/sshd.pid
? 830
? The second kind. Ps
? [[Email protected] ~]# PS aux |grep sshd
? Root 10180 0.0 0.0 7224 1024? Ss 16:00 0:00/usr/sbin/sshd
? The Third Kind. Pgrep
? [Email protected] ~]# pgrep-l sshd
? 10180 sshd
? [Email protected] ~]# pgrep sshd
? 10180
? The fourth kind. Pidof
? [Email protected] ~]# pidof sshd
? 10180
? (7) View process tree
? [Email protected]~] #pstree
? If you do not have this command, install it: #yum install-y Psmisc
? (8) Dynamic view process (top)
? The first part: System overall statistic information
? top-11:45:08 up 18:54, 4 users, load average:0.05, 0.05, 0.05
? tasks:176 Total, 1 running, 175 sleeping, 0 stopped, 0 zombie
? %CPU (s): 0.0 us, 0.3 sy, 0.0 NI, 99.7 ID, 0.0 wa, 0.0 hi, 0.0 si, 0.0th
? KiB mem:3865520 Total, 1100000 free, 580268 used, 2185252 Buff/cache
? KiB swap:4063228 Total, 4063228 free, 0 used. 2917828 Avail Mem
? Load weighted value interpretation:-less than 1 normal ————————————
? Load average:0.86, 0.56, 0.78 system last 1 minutes, 5 minutes, 15 minutes average load
? Part II: Introduction to Fields
? Virt:virtual Memory usage Virtual RAM
? Note: (1) The process "required" virtual memory size, including the library, code, data, etc. used by the process
? (2) If the process request 100M of memory, but actually only use 10M, then it will grow 100M,
? Instead of centuries of usage, these memories are needed, but not fully occupied.
? Res:resident Memory Usage resident RAM
? Note: (1) The memory size currently used by the process
? (2) Sharing with other processes
? (3) If 100M memory is applied, the actual use of 10M, it only grows 10M, and virt the opposite of how much memory
? Shr:shared Memory Shared
? Note: (1) In addition to the shared memory of the process itself, it also includes the shared memory of other processes
? (2) Calculate the physical memory size formula for a process: RES-SHR
? (9) Top interactive command
? K Terminates a process. The user will be prompted for the process PID to be terminated and what signal needs to be sent to the process.
? The normal termination process can use a 15 signal, and if not, use signal 9 to force end the process.
? The default value is signal 15. This command is masked in safe mode.
? I ignore idle and zombie processes. This is a switch-type command.
? Q quit the program.
? R reschedule the priority level of a process. The user is prompted to enter the process PID that needs to be changed and the process priority value that needs to be set.
Entering a positive value lowers the priority and, conversely, it gives the process a higher priority. The default value is 10.
? S switch to cumulative mode.
? s changes the delay time between two refreshes. The user will be prompted to enter a new time in S. If there are decimals,
In the conversion to m,s input 0 value, the system will be constantly refreshed, the default value is 5 S. It is important to note that if you set a time that is too small,
is likely to cause a constant refresh, so there is no time to see the display, and the system load will be greatly increased.
? F or F Add or remove items from the current display.
? O or O change the order in which items are displayed.
? L Toggle Display Average load and start time information.
? M toggles display memory information.
? T toggles the display of process and CPU status information.
? The C toggle Displays the command name and the full command line.
? M sorts based on the size of the resident memory.
? P is sorted according to the percentage size of CPU usage.
? T is sorted by time/accumulated time.
? W writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files.
Linux system Configuration and service management (top)