Linux command
ps 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
List all processes
ps aux
List processes for current user
ps -u [username]
Show process tree
ps -ef --forest
Show specific process
ps -p [pid]
Custom output format
ps -eo pid,ppid,cmd,%mem,%cpu
List threads
ps -eLf
Sort by memory usage
ps aux --sort=-%mem
Select processes by command name
ps -C [nginx]
说明
ps reports a snapshot of currently running processes on the system. It displays information such as process ID, user, CPU and memory usage, command name, and runtime for each process, providing a point-in-time view of system activity. The command accepts options in two distinct styles: BSD syntax (without dashes, e.g., aux) and POSIX syntax (with dashes, e.g., -ef). Both produce similar output but differ in column defaults and filtering behavior. The -o option allows fully custom output formats, selecting specific fields like pid, ppid, command, and resource usage. Common usage patterns include ps aux to list all processes with detailed info, ps -ef --forest to show the process hierarchy as a tree, and ps -p to inspect a specific process by PID.
参数
- a
- All users.
- u
- User-oriented format.
- x
- Include processes without tty.
- -e
- Every process.
- -f
- Full format.
- -p _PID_
- Select by PID.
- -u _USER_
- Select by user.
- --forest
- Process tree.
- -o _FORMAT_
- Custom output.
- -L
- Show threads with LWP and NLWP columns.
- -C _CMD_
- Select by command name.
- --sort _KEY_
- Sort output (e.g., --sort=-%mem).
FAQ
What is the ps command used for?
ps reports a snapshot of currently running processes on the system. It displays information such as process ID, user, CPU and memory usage, command name, and runtime for each process, providing a point-in-time view of system activity. The command accepts options in two distinct styles: BSD syntax (without dashes, e.g., aux) and POSIX syntax (with dashes, e.g., -ef). Both produce similar output but differ in column defaults and filtering behavior. The -o option allows fully custom output formats, selecting specific fields like pid, ppid, command, and resource usage. Common usage patterns include ps aux to list all processes with detailed info, ps -ef --forest to show the process hierarchy as a tree, and ps -p to inspect a specific process by PID.
How do I run a basic ps example?
Run `ps aux` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does a do in ps?
All users.