📅  最后修改于: 2023-12-03 15:13:36.780000             🧑  作者: Mango
In this tutorial, we will learn how to list all running processes on a Mac system using the Bash shell. We will explore various commands and flags to display information about processes such as PID, CPU usage, and memory usage.
To follow along with this tutorial, you will need:
We can use the ps
command to display a list of all running processes on a Mac system. The basic syntax of the ps
command is as follows:
ps [options]
To display a list of all running processes, simply run the ps
command without any options:
$ ps
PID TTY TIME CMD
13258 ttys000 0:00.28 -bash
13519 ttys000 0:00.00 ps
This will show a list of all running processes with the following columns:
To display more detailed information about processes, we can use various options with the ps
command. Here are some useful options:
-e
: Display all processes, including those not associated with a terminal-f
: Display a full listing of processes, including the command line arguments used to start the process-o
: Specify which columns to display$ ps -e
PID TTY TIME CMD
1 ?? 1:34.61 /sbin/launchd
2 ?? 0:02.14 (kernel_task)
...
$ ps -ef
UID PID PPID C STIME TTY TIME CMD
0 1 0 0 Wed02PM ?? 1:34.73 /sbin/launchd
0 2 0 0 Wed02PM ?? 0:02.15 (kernel_task)
...
$ ps -eo pid,ppid,%cpu,%mem,time,cmd
PID PPID %CPU %MEM TIME CMD
13258 1 0.0 0.1 00:00:28 -bash
13713 13654 0.0 0.0 00:00:00 ps -eo pid,ppid,%cpu,%mem,time,cmd
Listing running processes on a Mac system using the Bash shell is a simple task using the ps
command. Hopefully, this tutorial has provided useful information and commands to display information about processes.