Linux Process Management

Source: Internet
Author: User
Tags pkill

Linux Process Management

What is a process? A process is a program or command being executed. Every process is a running entity, with its own address space and occupying certain system resources. In short, a process is a running program. In Linux, commands such as ls are processes, but some command processes are closed immediately after running. The resident memory services such as apache will also generate processes. For example, if a user accesses a site under apache, a process is generated. There are various processes in Linux, especially on the server. We need to know the status of all processes in the system in real time. Therefore, this article will explain in detail the process management.

 

Before explaining process management, let's first discuss the role of process management. In general, process management has the following three functions:

  • Determine the server health status: This is the most important role in process management. It determines the server load and security status by analyzing the process status (memory, CPU usage, etc.
  • View all processes in the system: this is the basis of process management. You can view the status of all processes in the system to determine the management of processes.
  • Killing a process: an auxiliary means in process management. Killing a process is only a last resort. Generally, the process has a normal exit method, only when the process cannot end normally, to kill the process.

After learning about the role of process management, let's look at the use of process view commands. The process view commands mainly include ps, pstree, and top commands. Next we will explain them one by one.

 

Command Options:

  • -A: displays all processes of a terminal.
  • -U: displays the owner user and memory usage of the process.
  • -X: displays processes without control terminals.
  • -L: More detailed information is displayed in the long format.
  • -E: displays all processes.

Command combination: In general, ps commands have two combination formats: ps aux and ps-le.

  • Ps aux: view all processes in the system, using the BSD operating system format

Note: The ps aux command is different from the ps-aux command. In ubuntu, ps-aux will not report an error. In centos, ps-aux will prompt a warning message. You can use man ps to view the document description, but you do not have to worry about the difference between the two.

 

  • Ps-le: view all processes in the system, using the Linux Standard Format

In actual use, we do not need to know all the processes output by the ps command. What is the meaning of each output column. The following uses ps aux as an example to explain the meaning of the corresponding column:

  • USER: the USER that generates the process.
  • PID: the ID of the process.
  • % CPU: Percentage of CPU resources occupied by the process.
  • % MEM: Percentage of physical memory occupied by the process.
  • VSZ: The size of virtual memory occupied by the process, in KB.
  • RSS: the actual physical memory occupied by the process, in KB.
  • TTY: where the process is interrupted, where the tty1-tty7 represents the local control terminal, the tty1-tty6 is the character terminal, and the tty7 is the graphics terminal. Pts/0-255 represents a virtual terminal.
  • STAT: Process status. Common statuses include:
    • R: Run
    • S (capital): Sleep
    • T: stopped
    • S (lower case): contains sub-Processes
    • +: Background process
  • START: the START time of the process.
  • TIME: the computing TIME that the process occupies the CPU.
  • COMMAND: process name

(Note: Processes with PID equal to 1/sbin/init are the starting processes of the system and the parent processes of all processes in the System)

 

2.PstreeCommand production process tree

Command Options:

  • -P: displays the PID of the process.
  • -U: displays the user of the process.

Directly use the pstree command to output the system's process tree. processes with the same name are output in the form of a Number * process name. Use the pstree-p command to expand processes with different PIDs:

 

3.TopCommand to view the process status

Command Options:

  • -D seconds: specifies the number of seconds that the top command updates. The default value is 3 seconds.
  • -B: outputs in the batch processing mode, which is generally used with-n.
  • -N times: specifies the number of times the top Command is executed.

Commands in top Command interaction mode:

  • ? Or h: displays help documents in interactive mode.
  • P: sort by CPU usage. Default Value.
  • M: sort by memory usage.
  • N: sort by PID
  • Q: exit the top Command interaction mode.

Generally, the top interactive mode is displayed when you enter the top command on the terminal:

In this case, you can type commands in interactive mode to sort the output. In the top command, we focus on the top five lines of system information:

  • 11:31:20: Current System Time, updated every 3 seconds by default.
  • Up 113 days,: the system has been running for 113 days, 16 hours, and 20 minutes.
  • 3 users: Currently, three users are logged on.
  • Load average: 0.00, 0.00, 0.00: average load of the system in the previous 1 minute, 5 minutes, 15 minutes, generally considered for each CPU core, if the value is less than 1, the system load is small. If the value is greater than 1, the system load is large.
  • Task: 112 total: total number of processes in the system.
  • 2 running: Number of running processes.
  • 110 sleeping: Number of sleep processes.
  • 0 stopped: the process that is being stopped.
  • 0 zombie: zombie process.
  • Cpu (s): 0.3% us: cpu usage in user mode.
  • 0.3% sy: cpu usage in system mode.
  • 0.0% sy: Percentage of user processes that have changed their priorities.
  • 99.3% id: Percentage of idle cpu.
  • 0.0% wa: cpu usage of processes waiting for input/output.
  • 0.0% hi: Percentage of cpu used by the hard interrupt request service.
  • 0.0% si: Percentage of cpu used by the soft interrupt request service.
  • 0.0% st: virtual time percentage.
  • The fourth behavior is the physical memory information. The fifth behavior is the partition information, in kb. Note that buffers is the buffer memory size and cached is the cache memory size.

 

4.KillCommand to terminate the process

  • Kill-l (letter l): view all signals.

 

Here, focus on kill-1 (number 1) and kill-9. Kill-1 is used to restart a process (instead of killing it) and does not affect the use of existing processes. It is generally used to modify the configuration file of a service and kill-9 is used to forcibly terminate the process, the basic format is kill [number] process PID.

 

  • Killall command: the basic format is killall [Option] [Signal] process name. The options for killall include-I and-I,-I for interaction, and whether to kill a process.-I is used to ignore the case sensitivity of the process name.

  • Pkill command: the basic format is pkil [Option] [Signal] process name. Option-t terminal number is used to kick out the user according to the terminal number.

First, run the w command to view the current user. There are four remote user terminals. Currently, pts/4 is used because w command is being used. Then run the pkill command to kick out pts/0 and run the w command again to check whether the pts/0 user has been kicked out.

 

 

5. Modify priorityNiceCommand: the basic format is nice-n. In the preceding ps-le command, the columns with priority are PRI (priority) and NI (nice). The real priority is determined by PRI. The smaller the value, the higher the priority. You can only modify the NI value. The modified PRI is the original PRI + NI. Example of modifying the priority of an apache service process. Priority has no significant impact on daily use, so we will not describe it here. If you are interested, you can check the relevant information on your own.

     

 

Related Article

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.