CentOS Process Management

Source: Internet
Author: User

In Linux, the basic operating unit is process. By managing the processes in the system, you can understand and schedule the real-time running status of the system. Linux provides commands for viewing, adjusting, and stopping processes. This article still uses RHEL6 to describe the process management in Linux.

I. Process Overview

A program is a collection of executable machine code (or instructions) and data stored in the storage medium, while a process is a computer program executed by a computer processor. Their relationships are as follows:

  • Programs are executable code and data stored in external storage media, and static code.
  • A process is the running of program code in the processor and the code that is dynamically executed.
  • When executing a program, the operating system reads the code from an external storage medium (hard disk) to the internal storage medium (memory, the program code residing in the memory is dynamically executed as a process in the CPU.
  • Linux is a multi-process operating system. When each program starts, multiple processes can be created and run in Linux kernel space together with processes created by other programs. Each process is an independent task, and the rules set by the operating system kernel are executed by the CPU. Each separate process runs in its own virtual address space and can only interact with other processes through a Secure Kernel management mechanism.

Many system resources will be used during the lifetime of a process. It uses CPU to run commands and physical memory to save Execution Code and data. It will open and use files in the file subsystem, and directly or indirectly use physical devices in the system.

2. View Processes

1. Use the ps command
Common parameters:
ADisplay all processes of all users (including other users );
UDisplay processes by user name and start time;
XDisplays the process of the uncontrolled terminal;
EDisplay all processes, including processes without control;
FDisplay processes in a tree format;
LLong format output;
WTo avoid the truncation of detailed parameters, you can use multiple w to display them completely (such as ww or www );
OOptions to be viewed

Example:

[Root @ Vtest ~] # Ps aux | more

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.5 0.2 2864 1396 ? Ss 13:30 0:01 /sbin/initroot 2 0.0 0.0 0 0 ? S 13:30 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? S 13:30 0:00 [migration/0]root 4 0.0 0.0 0 0 ? S 13:30 0:00 [ksoftirqd/0]root 5 0.0 0.0 0 0 ? S 13:30 0:00 [migration/0]root 6 0.0 0.0 0 0 ? S 13:30 0:00 [watchdog/0]root 7 0.0 0.0 0 0 ? S 13:30 0:00 [events/0]root 8 0.0 0.0 0 0 ? S 13:30 0:00 [cpuset]

Information contained in ps command output:

USER: process owner; PID: process ID; PPID: parent process; % CPU: Percentage of CPU occupied by the process; % MEM: Percentage of memory occupied; NI: NICE value of the process, that is, the priority value of the process (-20 ~ 19), the larger the value, the lower the priority; VSZ: Process Virtual size; RS: number of resident pages; TTY: terminal ID. The question mark indicates that there is no end, that is, the system itself. STAT: Process status D Uninterruptible sleep (usually IO) R is running and can be crossed in the queue; S is in sleep state; T is stopped or tracked; W enters the memory switch (which is invalid since kernel 2.6); X dead processes (never seen); Z botnets; </strong> 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 multi-thread (using CLONE_THREAD, like NPTL pthreads do) + process group in the background; WCHAN: waiting process resources; START: START process TIME; TIME: CPU consumption TIME of the process; COMMAND: the name and parameters of the command used to start the process;

Other usage of the ps command:

(1)

[Root @ Vtest ~] # Ps aux | grep httpd### View the httpd process

root 1879 0.0 1.6 33096 8548 ? Ss 13:31 0:00 /usr/sbin/httpdapache 1887 0.0 0.8 33096 4212 ? S 13:31 0:00 /usr/sbin/httpd

(2)

[Root @ Vtest ~] # Ps axo pid, % cpu, % mem, comm | grep httpd# View only the pid, % cpu, % mem, and comm items

1879 0.0 1.6 httpd1887 0.0 0.8 httpd1888 0.0 0.8 httpd

For other parameters, you can perform the exercises on your own.

Tips: What is a zombie process. Generally, the cause of a botnet process is that the process should have been completed or terminated for some reason, but the parent process of the process cannot completely end the process, the process is always in memory. If you find that a process is followed by the CMD command, it indicates that the process is a zombie process. When the system is unstable, it is easy to cause so-called zombie processes. It may also be caused by incomplete program writing or poor user operation habits. If you find many zombie processes in the system, remember to find the parent process of the process, and then perform a tracking to eliminate the problem!

2. top Command

The top command displays the system running information in full screen on the current terminal, tracks the usage of system resources in real time, and displays the CPU and memory usage information, the list of processes running in the system and the status of each process are helpful for analyzing problems in the system.

[Root @ Vtest ~] # Top

The output information of top moments is as follows:

  1. Top-14:01:40Up31Min,1User,LoadAverage:0.04,0.01,0.00
  2. Tasks:122Total,1Running,121Sleeping,0Stopped,0Zombie
  3. Cpu (s ):0.0% us,0.3% sy,0.0% ni,99.3% id,0.0% wa,0.0% hi,0.3% si,0.0% st
  4. Mem:511140 kTotal,283656 kUsed,227484 kFree,24136 kBuffers
  5. Swap:2064376 kTotal,0 kUsed,2064376 kFree,148144 kCached
  6. PIDUSERPRNIVIRTRESSHRS% CPU% MEMTIME +COMMAND
  7. 2215Root20026721116880R0.70.20: 00. 08Top
  8. 2145Root2001155233162580S0.30.60: 00. 25Sshd
  9. 1Root200286413961184S0.00.30: 01. 67Init
  10. 2Root200000S0.00.00: 00. 00Kthreadd
  11. 3RootRT0000S0.00.00: 00. 00Migration/0
  12. 4Root200000S0.00.00: 00. 00Ksoftirqd/0
  13. 5RootRT0000S0.00.00: 00. 00Migration/0
  14. 6RootRT0000S0.00.00: 00. 00Watchdog/0
  15. 7Root200000S0.00.00: 00. 00Events/0
  16. 8Root200000S0.00.00: 00. 00Cpuset
  17. 9Root200000S0.00.00: 00. 00Khelper
  18. 10Root200000S0.00.00: 00. 00Netns
  19. 11Root200000S0.00.00: 00. 00Async/mgr
  20. 12Root200000S0.00.00: 00. 00Pm
  21. 13Root200000S0.00.00: 00. 00Sync_supers
  22. 14Root200000S0.00.00: 00. 00Bdi-default
  23. 15Root200000S0.00.00: 00. 00Kintegrityd/0
  24. 16Root200000S0.00.00: 00. 01Kblockd/0
  25. 17Root200000S0.00.00: 00. 00Kacpid
  26. 18Root200000S0.00.00: 00. 00Kacpi_policy
  27. 19Root200000S0.00.00: 00. 00Kacpi_hotplug
  28. 20Root200000S0.00.00: 00. 00Ata/0
  29. 21Root200000S0.00.00: 00. 00Ata_aux
  30. 22Root200000S0.00.00: 00. 00Ksuspend_usbd
  31. 23Root200000S0.00.00: 00. 00Khubd

We divide the output information into three parts:

1-5 behavior Part 1:

Row 3:
Top-14:01:40: current time, which is updated every three seconds by default.
Up31Min: How long the system has been running, in the format of: minute
1 user: Current number of login users
Load average: 0.00, 0.00, 0.00:System load, that is, the average length of the task queue. The three values are the average values from 1 minute, 5 minutes, and 15 minutes ago to the present.

Row 3:
Tasks:122Total: total number of processes in the system
1Running: Number of Running Processes
121Sleeping: Number of sleeping Processes
0Stopped: Number of stopped Processes
0Zombie: Number of zombie Processes

Row 3:
Cpu (s): 0.0% us(User mode) CPU usage percentage
0.3% sy(System mode) CPU usage of the kernel
0.0% ni(Nice) Percentage of CPU used by processes whose priorities have changed
99.3% idle task idle CPU percentage
0.0% wa(I/O waiting) Percentage of CPU time waiting for input and output (I/O problems will seriously affect your server performance, because I/O consumes CPU)
0.0% hi(Servicing IRQs)
0.3% si(Servicing soft IRQs)
0.0% st(Steal (time given to other DomU instances ))

Row 3:
Mem:511140 kTotal: total physical memory
283656 kUsed: Used physical memory
227484 kFree: Unused physical memory
24136 kBuffers: physical memory occupied by kernel Cache

Row 3:
Swap:2064376 kTotal: total swap partition capacity
0 kUsed: used swap partition capacity
2064376 kFree: unused swap partition capacity
148144 kCached: Total cache capacity. If unused physical memory exists, cached occupies physical memory. If the unused physical memory is 0, cached occupies part of the swap partition, then, the capacity of cached is the physical memory occupied by it plus the swap partition occupied by it.

6th behavior Part 2:

This is the top internal command input part. Common Commands include:
SChange the top Command refresh frequency (3 seconds by default), Change delay from 3.0 to: Enter the corresponding number
LDisable or enable the first line of top information
TDisable or enable the second line of Tasks and the third line of Cpus Information
MDisable or enable Part 1 Mem and line 5 Swap information
NProcess list in the order of PID size
PProcess list in the order of CPU usage
MProcess list in the order of memory usage
RReverse the arrangement
UDisplays the processes of the specified user. By default, all user processes are displayed.
CDisplays the full path of a process. By default, only the process name is displayed.
NOr # set the number of processes displayed in the process list, but the maximum number is full screen.
FAdjust the top command to display the list items. Such as adding a GROUP column or UID column. However, the next time you use the top command, it turns out to be the default one.
KEnd Process
RAdjust the process priority (Linux and AIX are from-20 to 19, HP-UX is 0 to 39), as to how to get it, you can view through man nice.
HShow Help
QExit top

The rest are process information:

Meanings of each column in the top Process Information List:
PIDProcess id
PPIDParent process id
RUSERReal user name
UIDUser ID of the process owner
USERUser Name of the process owner
GROUPGroup Name of the process owner
TTYThe terminal name of the startup process. Processes not started from the terminal are displayed?
PRPriority
NINice value. Negative value indicates high priority, positive value indicates low priority (Linux and AIX are from-20 to 19, HP-UX is 0 to 39)
PThe last CPU used is only meaningful in multiple CPU environments.
% CPUCPU usage from the last update to the present
TIMETotal CPU time used by the process, in seconds
TIME +Total CPU time used by the process, in 1/100 seconds
% MEMPercentage of physical memory used by the Process
VIRTTotal virtual memory used by the process, in kb. VIRT = SWAP + RES
SWAPIn the virtual memory used by the process, the swap size, in kb.
RESPhysical memory used by the process, not swapped out, in kb. RES = CODE + DATA
CODEPhysical memory occupied by executable code, in kb
DATAPhysical memory occupied by parts other than executable code (Data Segment + stack), in kb
SHRSize of shared memory, in kb
NFLTPage error count
MCM tNumber of modified pages written to the present last time
SProcess status
D = uninterrupted sleep
R = run
S = sleep
T = tracking/stopping
Z = zombie Process
COMMANDCommand name/command line
WCHANIf the process is sleeping, the system function name displayed in sleep
FlagsTask flag

By default, only importantPID, USER, PR, NI, VIRT, RES, SHR, S, % CPU, % MEM, TIME +, COMMANDColumn. You can use the internal f command we mentioned above to adjust the list options.

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.