0Pricing
Linux Command Line Mastery · 课时

理解进程:`ps`、`top`、`htop`

探索用于查看、监控和理解 Linux 系统中活动进程的命令。

理解进程:`ps`、`top`、`htop` 是 CoddyKit 上的免费 Linux Command Line Mastery 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Command Line Mastery 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Command Line Mastery 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

What Are Processes?

Welcome! In this lesson, we'll explore how to view and monitor programs running on your Linux system. These running programs are called processes.

Understanding processes is crucial for system administration, troubleshooting, and managing resource usage.

`ps`: Snapshot of Processes

The simplest way to see active processes is with the ps command. It gives you a snapshot of current processes.

By default, ps shows processes owned by your user in the current terminal session.

ps

More `ps` Details: `aux` and `-ef`

To see all processes on the system, including those owned by other users and system processes, we use options like aux or -ef.

  • a: Show processes for all users.
  • u: Display user/owner.
  • x: Show processes without a controlling terminal.

The -ef option is a common alternative on some systems, providing similar comprehensive output.

ps aux

Deciphering `ps` Output

When you run ps aux, you'll see several columns:

  • USER: The owner of the process.
  • PID: The unique Process ID.
  • %CPU: CPU usage percentage.
  • %MEM: Memory usage percentage.
  • CMD: The command that started the process.

These details help you identify what's running and by whom.

PID and PPID Explained

Every process has a unique PID (Process ID). It's like a social security number for a process.

Many processes are started by other processes. The process that starts another is called its parent process. The child process will have a PPID (Parent Process ID) that matches the parent's PID.

This creates a process tree, showing how processes are related.

ps -o pid,ppid,cmd

`top`: Real-time Monitoring

While ps gives a snapshot, top provides a dynamic, real-time view of your system's processes.

It continuously updates, showing CPU and memory usage, uptime, and a list of processes sorted by CPU usage (by default).

This is great for spotting processes consuming a lot of resources.

top

Navigating `top`

top is interactive! Here are some basic keys:

  • Press q to quit.
  • Press M to sort processes by memory usage.
  • Press P to sort processes by CPU usage (default).
  • Press k to "kill" a process (you'll need the PID).

Remember to be careful when using k!

`htop`: An Enhanced `top`

htop is an improved, interactive process viewer that's often preferred over top due to its user-friendliness.

It offers a more colorful and intuitive interface, making it easier to see CPU and memory usage visually.

You might need to install it first (e.g., sudo apt install htop on Debian/Ubuntu).

htop

Why Use `htop`?

htop provides several advantages:

  • Visual Bars: Clear graphs for CPU, memory, and swap.
  • Scrolling: Easily scroll horizontally and vertically.
  • Mouse Support: Click to sort columns or select processes.
  • Easy Filtering/Searching: Quickly find specific processes.
  • Tree View: See process hierarchy clearly.

It's a powerful tool for monitoring system health.

Process Command Check

You've learned about ps, top, and htop. Let's see if you can distinguish their primary uses.

Processes: Snapshot vs. Real-time

Great job! You now understand how to monitor processes on Linux.

  • ps: Gives a static snapshot of processes. Use ps aux or ps -ef for comprehensive lists.
  • top: Provides a real-time, interactive view of processes, sorted by resource usage.
  • htop: An enhanced, more user-friendly version of top with visual bars, mouse support, and easier navigation.

These tools are essential for any Linux user!

常见问题解答

「理解进程:`ps`、`top`、`htop`」课时是免费的吗?

是的 — 「理解进程:`ps`、`top`、`htop`」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Command Line Mastery 课程的其余内容,请升级到 CoddyKit PRO。 Linux Command Line Mastery 课程共包含 4 节课。

「理解进程:`ps`、`top`、`htop`」这节课中我会学到什么?

探索用于查看、监控和理解 Linux 系统中活动进程的命令。 你通过在浏览器中直接运行的动手代码来练习 Linux Command Line Mastery,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Linux Command Line Mastery 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Linux Command Line Mastery 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「理解进程:`ps`、`top`、`htop`」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Linux Command Line Mastery 课中编写并运行代码吗?

能。每节 Linux Command Line Mastery 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 理解进程:`ps`、`top`、`htop`
  2. 管理进程:`kill`、`bg`、`fg`
  3. 监控系统资源:`df`、`du`、`free`
  4. 使用 nice、renice 与信号管理进程优先级
← 返回 Linux Command Line Mastery