Linux ps commands

Source: Internet
Author: User
Tags egrep

Linux ps commands

The ps command in Linux is short for Process Status. The ps command is used to list the processes currently running in the system. The ps command lists the snapshots of the current processes, that is, those processes that run the ps command at that time. If you want to dynamically display process information, you can use the top command.

To monitor and control processes, you must first understand the current process, that is, you need to view the current process, and the ps command is the most basic and very powerful process viewing command. You can use this command to determine which processes are running and running, whether the process is terminated, whether the process is dead, and which processes are occupying excessive resources. In short, most of the information can be obtained by executing this command.

Ps provides a one-time View of the process. The results are not dynamically consecutive. To monitor the process time, use the top tool.

[Root @ linux ~] # Ps aux
[Root @ linux ~] # Ps-lA
[Root @ linux ~] # Ps axjf
Parameters:
-A: all processes are displayed, which has the same effect as-e;
-A: All processes not related to terminal;
-U: process related to valid users;
X: usually used with the parameter a to list complete information.
Output Format planning:
L: long and detailed information of the PID is listed;
J: Job format)
-F: make a more complete output.
Note:
Ps supports many OS types, so its parameters are too many!
And is there a lot of difference! For detailed usage, refer to man ps!

Example 1: List the current PID and related information for your login

[Root @ linux ~] # Ps-l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 0 5881 5654 0 76 0-1303 wait pts/0 00:00:00 su
4 S 0 5882 5881 0 75 0-1349 wait pts/0 00:00:00 bash
4 R 0 6037 5882 0 76 0-1111-pts/0 00:00:00 ps
 
# There is actually a lot of information above! The meanings of relevant information are as follows:
# F indicates the flag of the program, and 4 indicates that the user is super user;
# S indicates the state of the Program (STAT). The meaning of each STAT is described in the article;
# No problem with PID !? The ID of this program! The PPID under is the parent program ID;
# Percentage of resources used by C CPU
# PRI: the abbreviation of Priority (Priority execution order), which will be detailed later;
# NI: Nice value. We will continue to introduce it in the next section.
# ADDR: This is the kernel function, indicating the part of the program in the memory. If it is a running program, it is generally!
# SZ memory used out;
# Whether the program is currently running. If-indicates that the program is running;
# TTY login terminal location;
# Cpu time used out.
# What are the commands issued by CMD !?
# What is the correlation between PID and PPID of each program! Among the three programs listed above, they are correlated! Copy code
Example 2: List all programs in memory

[Root @ linux ~] # Ps aux
User pid % CPU % MEM VSZ RSS TTY STAT START TIME COMMAND
Root 1 0.0 0.1 1740 540? S Jul25 0: 01 init [3]
Root 2 0.0 0.0 0 0? SN Jul25 0: 00 [ksoftirqd/0]
Root 3 0.0 0.0 0 0? S <Jul25 0: 00 [events/0]
... Omitted in the middle .....
Root 5881 0.0 0.3 5212 1204 pts/0 S su
Root 5882 0.0 0.3 5396 1524 pts/0 S bash
Root 6142 0.0 0.2 4488 916 pts/0 R + ps aux

# USER: which USER account does the process belong?
# PID: the number of the process.
# % CPU: Percentage of CPU resources used by the process;
# % MEM: Percentage of physical memory occupied by the process;
# VSZ: virtual memory used by the process (Kbytes)
# RSS: the fixed amount of memory occupied by the process (Kbytes)
# TTY: The process operates on that terminal. If it is irrelevant to the terminal, it will display ?, In addition, the tty1-tty6 is the login program on the machine, if the pts/0 and so on, it indicates the program connected to the host by the network.
# STAT: Current State of the program. The main states are:
# R: The program is currently in operation or can be operated;
# S: The program is currently in sleep state (idle state !), However, it can be awakened by some signals.
# T: The program is currently being detected or stopped;
# Z: The program should have been terminated, but its parent program cannot be terminated normally, resulting in the zombie (zombie) program status.
# START: the time when the process is triggered;
# TIME: the actual CPU usage TIME of the process.
# COMMAND: What is the actual COMMAND of the program? Copy code
Example 3: The content displayed in Example 1 is only for the current user. The following shows the programs of all users.

[Root @ linux ~] # Ps-lA
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 1 0 0 76 0-435 -? 00:00:01 init
1 S 0 2 1 0 94 19-0 ksofti? 00:00:00 ksoftirqd/0
1 S 0 3 1 0 70-5-0 worker? 00:00:00 events/0
......... Example 4: List program display similar to the program tree

[Root @ linux ~] # Ps-axjf
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 1 0 0? -1 S 0: 01 init [3]
1 2 0 0? -1 SN 0: 00 [ksoftirqd/0]
... Omitted in the middle .....
1 5281 5281 5281? -1 Ss 0 0: 00/usr/sbin/sshd
5281 5651 5651 5651? -1 Ss 0 0: 00 \ _ sshd: dmtsai [priv]
5651 5653 5651 5651? -1 S 500 \ _ sshd: dmtsai @ pts/0
5653 5654 5654 5654 pts/0 6151 Ss 500 \ _-bash
5654 5881 5881 5654 pts/0 6151 S 0 \ _ su
5881 5882 5882 5654 pts/0 6151 S 0 \ _ bash
5882 6151 6151 5654 pts/0 6151 R + 0 \ _ ps-axjf copy code
Example 5: Find the PID related to the cron and syslog services.

[Root @ linux ~] # Ps aux | egrep '(cron | syslog )'
Root 1539 0.0 0.1 1616 616? Ss Jul25 0: 03 syslogd-m 0
Root 1676 0.0 0.2 4544 1128? Ss Jul25 0: 00 crond
Root 6157 0.0 0.1 3764 664 pts/0 R + egrep (cron | syslog) by default, ps only lists the PID related to the current bash shell, so when I use ps-l, there are only three PIDs (Example 1 ).

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.