Introduction to process management in Linux systems

Source: Internet
Author: User

In a Linux system, an instance of a program that is currently running is called a process. For example, when you start Apache, the system assigns it a process ID. You can then use this ID to monitor and control this program.

Process monitoring and control is a core task for any Linux system administrator. An administrator can terminate ("kill"), restart a process, or even assign a different priority to it. Standard Linux Commands "PS" and "top" are often used to view the current list of processes. Let me explain how to use these commands and other commands to manage processes in a Linux system.

Monitoring processes with PS

A standard tool for monitoring Linux is "PS", which is the abbreviation for the status of the process. This command returns information about the program that is running. This information may include the user name in which the program is running, how many CPUs were used, and how long it was running. This information is useful if you want to manually terminate the program or determine which program slows the system down.

If you just type the "PS" command, then only the processes running under the current terminal can be listed. The following example is the result of running "PS" output through a remote shell:

$ ps
PID TTY TIME CMD
4684 pts/14 00:00:00 bash
27107 pts/14 00:00:00 ps

As you can see from the output, the process assigned to this user/terminal is only the bash shell and the PS command itself. You can also see the PID (Process ID) and TTY, time, and CMD listed for each process. TTY indicates which terminal the process is running on, time indicates how much CPU times the process has been used, and CMD is the name of the command that started the process.

Users can see that standard PS commands can only list basic information. To get detailed information on the processes running on a Linux system, you must add some command-line arguments.

Adding ps commonly used aux parameters can show other user-initiated processes (a), view the system's own process (x), and the user who started the process and when it started (U).

More information is now available, adding user,%cpu,%mem, VSZ, RSS, Stat, and start fields. Now let's take a look at what this information means.

First, the user can see all the processes, not just those running on the terminal. The user field indicates who initiated the command. Many processes and systems are started together, and the root or some system accounts are listed as user. Of course, some of the other processes are run separately. The information itself can help you narrow down the problem. If a user starts a script, it consumes a large amount of I/O to the server. If you can find out who is running this program right away, then you can quickly solve the problem.

Several domains,%cpu,%mem, vsz, and RSS, are related to system resources. First, users can see how much CPU a process is consuming. This information is displayed in real time, so it is difficult to capture spikes with PS. Users may find that the process that is causing the problem needs to run the PS command continuously.

In addition to CPU usage, you can see memory usage and its vsz (virtual memory size) and RSS (resident set size). VSZ indicates how much memory space is required if a program is fully resident in memory, and RSS indicates how much memory is currently occupied. If you can understand how much memory a process is currently consuming, you can determine whether the process is running correctly or an exception has occurred. Programs typically consume more memory and CPU than normal. While programmers are trying to make sure that the code uses resources correctly, sometimes it is up to the administrator to decide whether to terminate or restart the process.

Users may notice that in the output of the PS aux command, most TTY domains have a "? "。 This is because these programs either start running when the system is started, or are started by the initialization script (init scripts). These processes do not have control terminals, so they are marked. In addition, the Linux-sanity-check command has a TTY value of PTS/14. This command is run by a remote connection and has a terminal associated with it. This information is useful when your machine opens multiple connections and you want to determine which window the command is running in.

Stat shows the current state of the process. In our example, many processes are in a state of sleep, and "S" in the stat domain indicates this state. This merely indicates that these processes are waiting for certain events to occur-either user input or the availability of system resources. The Linux-sanity-check command has a state of R that indicates that the process is currently running. Sometimes you can browse the list and look for processes that are in the R state. If most processes are in a sleep state and a problem occurs, it is best to focus on those processes that are running. That State does not necessarily indicate a problem, but sometimes if the process is running for too long it may mean that some deep-seated problems have occurred.

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.