📜  bash list processes mac - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:13:36.780000             🧑  作者: Mango

Bash List Processes on Mac

Introduction

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.

Requirements

To follow along with this tutorial, you will need:

  • A Mac computer
  • A terminal emulator such as Terminal or iTerm2
  • Basic knowledge of the Bash shell
Displaying a List of Running Processes

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:

  • PID: The unique process identifier assigned to each process by the system
  • TTY: The terminal associated with the process
  • TIME: The amount of CPU time the process has used
  • CMD: The name of the command that started the process
Displaying More Information about Processes

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
Display all processes
$ ps -e
  PID TTY           TIME CMD
    1 ??         1:34.61 /sbin/launchd
    2 ??         0:02.14 (kernel_task)
...
Display a full listing of processes
$ 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)
...
Specify which columns to display
$ 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
Conclusion

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.