Linux Command--ps command

Source: Internet
Author: User

The first thing to understand is what the process
A process is a running program. This means that everything running on a Linux system is a process. As compared to a process, a job is a series of commands executed in a certain order. A simple command may involve multiple processes, especially when using pipelines and redirects. For example, command:

# Nroff–man Ps.1 | grep Kill | More

will produce three processes, one for each command.

There are several processes in the Linux operating system, each with its own qualities and characteristics. Here are three types of processes for the Linux system:

Interactive process: A process that is started and controlled by the shell. Interactive processes can be run both in the foreground and in the background.

Batch process: A sequence of processes that are scheduled to be completed at a specified time, regardless of the terminal.


Daemon: Start when booting the system to perform immediate operating system tasks such as LPD, inetd, named, and so on.

1. Introduction to PS

To monitor and control the process, you must first understand the current process, that is, you need to see the current process, and the PS command is the most basic and very powerful process view command. Use this command to determine which processes are running and running, whether the process is complete, if the process is zombie, which processes are consuming too many resources, and so on. In short, most of the information can be obtained by executing the command.

2. Output of PS command

The PS command usually outputs the result in the form of a row. Each process in the system has a unique identifier so that Linux can recognize them. Linux processes the process by assigning unique numbers to each process, which is called the process ID number (or PID number). PID number when the system is booted starting from 0, add 1 bits to each additional process until the system determines a number, such as 65564. Then, the PID number starts again from 0, cycle by loop, continuously. Usually the smaller PID process is the core and daemon of the system, they exist when the system is booted, and they are active as long as the system is still running. When users manage processes (such as terminating them), the PID number must be used. The TTY column of the PS command output tells the user which terminal the process starts with. If you are logged in as a normal user, you are usually the user's own terminal or console. If you work on a multi-console system, users will see all the processes that they have started in each console.

The stat column of the PS command output tells the user the status of the current process. The two most common states of a process are S (sleeping) representing dormant processes and R (running) for running processes. The process that is running is the process that is currently executing in the CPU, and the sleeping process is a process that is not currently active. Processes can be converted multiple times per second between sleeping and running states.

The time column of the PS command output tells the user that the process takes up a total CPU time, which is usually short, because most processes run at the end of a short time.

The commands column, which contains the names of all the commands that the user is running. The commands that appear in the commands column are usually those used by the user, but some commands also cause other processes, called child processes.

3. PS command and its parameters

The PS command is most commonly used to monitor the work of the background process because the background process is not communicating with these standard input/output devices on the on-screen keyboard, so you can use the PS command if you need to detect the situation.

The syntax format for this command is as follows:

Ps

The following is a description of the command options:
-e Displays all processes.
-F full format.
-H does not display the caption.
-L long format.
-W wide output.
A shows all processes on the terminal, including the processes of other users.
R displays only the processes that are running.

3. Common PS Command parameters

The three most commonly used parameters are U, a, x, and the following will illustrate their specific usage using an example.

Log in to the system as root to see the status of the current process

PS PID TTY Time COMMAND 5800 xx:xx:  5835xx: xxPS 

As you can see, the displayed items are divided into four items, which are PID (process ID), TTY (terminal name), time (Process execution times), command (the process input).

You can use the U option to view the process owner and some other details as follows:

 $ ps   Uuser PID %cpu%mem USZ RSS TTY STAT START time commandtest  5800  0.0  0.4  1892  1040  ttyp0 S Nov27 0 : 00 -bashtest  5836  0.0  0.3  2528  856  ttyp0 R Nov27 0 : 00  ps  u 

There is a horizontal line in front of the bash process, which means that the process is the user's login shell, so there is only one process for a logged-on user with a dash. You can also see the%CPU,%mem two options, which are the percentage of CPU time and total time consumed by the process, which refers to the process
The percentage of memory and total memory consumed.

PS x (the result is too long is not listed ...)

In this case we will see all the control terminal processes;

In particular, the-l option can tell you which process is causing a process, which is only useful if you want to identify a child process:

$PS-LF UID PID PPID PRI NI SIZE RSS wchan STAT TTY time COMMA ND0       501    A     1            the     0      364    472114d9c S V010:xx–bash0       501   121    A            in     0       -     208   0R V010:xx            PS–l

PPID (parent process ID) is the ID number of the process's parent. In this example, the first process listed (PID 41) is the parent process of the second process (PID 121). You can also see that the PID of the ps–l parent process Login Bourne shell is 1, which is the init process of the operating system. If Init is terminated, all processes will be killed. Simply put, if Init dies, the system shuts down.

Linux Command--ps command

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.