In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what is the use of the ps command in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The Linux common command ps command is used to report the process status of the current system. You can interrupt and delete unnecessary programs at any time with kill instructions.
Ps reports the process status of the current system
Add that the ps command is the most basic but also very powerful process view command, which allows you to determine which processes are running and running status, whether the process ends, whether the process is dead, which processes take up too much resources, and so on. In short, most of the information can be obtained by executing the command.
Syntax ps (option) option-a: displays all programs executed under the terminal, except for the phase job leader. A: displays all programs under the current terminal, including those of other users. -A: show all programs. -c: displays the CLS and PRI fields. C: when programs are listed, the real instruction name of each program is displayed, without the identification of paths, options, or resident services. -C: specifies the name of the execution instruction and lists the status of the program in which the instruction is executed. -d: displays all programs, excluding those of phase operation leaders. -e: this option has the same effect as specifying the "A" option. E: when listing programs, display the environment variables used by each program. -f: displays the UID,PPIP,C and STIME fields. F: display the tree structure with ASCII characters to express the relationship between programs. -g: this option has the same effect as specifying the "- G" option, and can also be specified using the name of the phase operation leader. G: displays all programs under the current terminal, including those of group leaders. -G: lists the status of programs that belong to this group, or you can specify it using the group name. H: the title column is not displayed. -H: displays the tree structure, indicating the interrelationship between programs. -j or j: displays the status of the program in a work-controlled format. -l or l: displays the status of the program in a detailed format. L: list the relevant information about the field. -m or m: displays all threads. N: USER and WCHAN fields are represented by numbers. -N: displays all programs except those under the ps instruction terminal. -p: specify the program identification number and list the status of the program. P: this option has the same effect as specifying the "- p" option, with only slight differences in list format. R: list only the programs that are being executed by the current terminal. -s: specify the program identification code of the phase operation and list the status of the programs belonging to that phase operation. S: display the status of the program in the format of the program signal. S: when listing the program, include the interrupted subroutine data. -t: specify the terminal number and list the status of the programs that belong to the terminal. T: this option has the same effect as specifying the "- t" option, except for slight differences in list format. -T: displays all programs under the current terminal. -u: this option has the same effect as specifying the "- U" option. U: displays the status of the program in a user-based format. -U: lists the status of the programs that belong to the user, or you can specify them using the user name. U: lists the status of programs that belong to this user. V: displays the status of the program in the format of virtual memory. -V or V: displays version information. -w or w: displays the status of the program in a broad format. X: displays all programs, not distinguished by terminals. X: displays the status of the program in the old Linux i386 login format. -y: when used with the option "- l", the F (flag) field is not displayed, and the ADDR field is replaced by the RSS field. -: this option has the same effect as specifying the "p" option. -- cols: sets the maximum number of characters per column. -- columns: this option has the same effect as specifying the "--cols" option. -- cumulative: this option has the same effect as specifying the "S" option. -- deselect: this option has the same effect as specifying the "- N" option. -- forest: this option has the same effect as specifying the "f" option. -- headers: the title column is displayed repeatedly. -- help: online help. -- info: displays troubleshooting information. -- lines: sets the number of columns in the display screen. -- no-headers: this option has the same effect as specifying the "h" option, except for slight differences in list format. -- group: this option has the same effect as specifying the "- G" option. -- Group: this option has the same effect as specifying the "- G" option. -- pid: this option has the same effect as specifying the "- p" option. -- rows: this option has the same effect as specifying the "--lines" option. -- sid: this option has the same effect as specifying the "- s" option. -- tty: this option has the same effect as specifying the "- t" option. -- user: this option has the same effect as specifying the "- U" option. -- User: this option has the same effect as specifying the "- U" option. -- version: this option has the same effect as specifying the "- V" option. -- widty: this option has the same effect as specifying the "- cols" option. Because the ps command can support a considerable number of system types, so the number of options is outrageous!
Instance ps axo pid,comm Pcpu # View the PID of the process, Name and CPU occupancy ps aux | sort-rnk 4 # sort processes by memory resource usage ps aux | sort-nk 3 # sort processes by CPU resource usage ps-A # display all process information ps-u root # display specified user information ps-efL # View the number of threads ps-e-o "% C:% p:% z:% a" | sort-K5-nr # View processes and arrange ps-ef by memory usage # display all process information Together with command line ps-ef | grep ssh # ps and grep commonly used in combination to find a specific process ps-C nginx # sort by name or command search process ps aux-- sort=-pcpu,+pmem # CPU or memory,-descending + ascending order ps-f-- forest-C nginx # displays the hierarchical relationship of processes in tree style ps-o pid,uname,comm-C nginx # shows the child process of a parent process ps-e-o pid,uname=USERNAME,pcpu=CPU_USAGE,pmem,comm # redefines the label ps-e-o pid,comm Etime # shows the running time of the process ps-aux | grep named # View the details of the named process ps-o command-p 91730 | sed-n 2p # get the service name through the process id. List the PID and related information that currently belongs to you this time.
Ps-l # UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD # 501 566 559 4006 0 31 0 4317620 228-Ss 0 ttys001 0V 00.05 / App...cOS/iTerm2-- server / usr/bin/login-fpl kenny / Ap...s/MacOS/iTerm2-- launch_shel # 501 592 577 4006 0 31 0 4297048 52-S 0 ttys001 015 00.63-zshF represents the flag of this program 4 indicates that the user is super user
S represents the status of the program (STAT), and the meaning of each STAT will be introduced in the text.
The UID program is owned by the UID
PID is the ID of this program!
PPID is the ID of its parent program.
Percentage of resources used by C CPU
PRI this is the abbreviation of Priority (priority execution order), which will be described in more detail.
NI this is the Nice value, which we will continue to introduce in the next section.
ADDR this is kernel function, indicating which part of the program is in memory. If it is a running program, it is usually "-"
The amount of memory used by SZ
WCHAN, is this program currently in operation? if yes, it indicates that it is in operation.
The terminal location of the TTY login
The CPU time used by TIME.
What are the instructions issued by CMD?
By default, ps lists only the PID related to the current bash shell, so when I use ps-l, there are only three PID.
List all the programs currently in memory
Ps aux # USER PID% CPU% MEM VSZ RSS TT STAT STARTED TIME COMMAND # kenny 6155 21.3 1.7 7969944 284912? S 2 03 pm 19914 / Appl...OS/WeChat # kenny 559 20.4 0.8 4963740 138176? S 2 03 33 pm 33 28.27 / Appl...S/iTerm2 # _ windowserver 187 18.0 0.6 7005748 95884? Ss 2 03 pm 288 daemon 44.97 / Syst...Light.WindowServer-daemon # kenny 1408 10.7 2.1 5838592 347348? S 203 138pm kenny 51.63 / Appl...nts/MacOS/Google Chrome # 527 5.80.5 5771984 79452? S 203 pm 2 51.58 / Syst...pp/Contents/MacOS/FinderUSER: the process belongs to that user account.
PID: the number of the process
% CPU: percentage of CPU resources used by this process
% MEM: percentage of physical memory occupied by this process
VSZ: the amount of virtual memory used by the process (Kbytes)
RSS: the fixed amount of memory occupied by the process (Kbytes)
TTY: the process runs on that terminal. If it has nothing to do with the terminal, it displays. In addition, tty1-tty6 is the login program on this machine. If it is pts/0, it is the program connected to the host through the network.
STAT: the current state of the program, the main states are
R: the program is currently in operation or can be operated
S: this program is currently sleeping (idle status), but can be awakened by certain signals (signal).
T: the program is currently being detected or stopped.
Z: the program should have been terminated, but its parent program could not terminate it normally, resulting in the state of the zombie program.
START: the time when the process was triggered and started
TIME: the time that the process actually uses CPU to operate
COMMAND: the actual instruction of the program
List the program display similar to the program tree
Ps-axjf # USER PID PPID PGID SESS JOBC STAT TT TIME COMMAND UID C STIME TTY # root 10 100 Ss? 10 USER PID PPID PGID SESS JOBC STAT TT TIME COMMAND UID C STIME TTY 51.90 / sbin/launchd 00 2 03 PM? # root 50 1 000 Ss? 0:10. 07 / usr/sbin/syslog 0 02 03 p.m.? # root 51 1 51 00 Ss? 0 usr/libexec/Use 00 2 03 PM? Find out the PID numbers related to cron and syslog
Ps aux | egrep'(cron | syslog)'# root 50 0.0 4305532 1284? Ss 003 0kenny 10.08 / usr/sbin/syslogd # kenny 0.00.0 4258468 184s007R + 9:23 0kenny 00.00 egrep (cron | syslog) displays all processes and outputs them to the ps001.txt file
Ps-aux > ps001.txt outputs the specified fields.
The above is all the content of the article "what is the use of ps commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.