Linux Command Line Mastery · 课时

使用 nice、renice 与信号管理进程优先级

使用 nice 和 renice 控制进程获得的 CPU 资源,并学习信号如何让您与运行中的进程通信,而不仅仅是终止它们。

第 4 / 4 课13 个步骤

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

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

Beyond Starting and Stopping

You already know how to view processes with ps/top and stop them with kill. But sometimes a process should simply run more politely so it does not starve others of CPU.

That is what nice and renice are for.

What Is a Niceness Value?

Every process has a niceness from -20 (highest priority) to 19 (lowest priority). A nicer process yields CPU to others. Default is 0.

Starting a Process with nice

nice -n N command launches a command with niceness N. Higher numbers are friendlier to the rest of the system.

nice -n 10 tar -czf backup.tar.gz /var/log

Viewing Niceness

The NI column in top shows niceness. With ps you can request it explicitly.

ps -o pid,ni,comm -p 1

Changing Priority with renice

renice adjusts the niceness of an already running process by PID.

renice -n 5 -p 1234

Why You Need Root to Raise Priority

Any user can make a process nicer (raise the number). Only root can give a process a negative niceness, because that takes CPU away from everyone else.

sudo renice -n -5 -p 1234

Signals: More Than kill

The kill command really sends a signal. SIGTERM (15) asks nicely to stop; SIGKILL (9) forces it; SIGHUP (1) often tells a daemon to reload config.

kill -l

Reloading Without Restarting

Sending SIGHUP to many services makes them re-read their configuration without a full restart, avoiding downtime.

kill -HUP 4567

Pausing and Resuming a Process

SIGSTOP freezes a process and SIGCONT resumes it, handy for temporarily relieving load.

kill -STOP 4567
kill -CONT 4567

Targeting by Name

pkill and killall let you send signals by process name instead of PID.

pkill -HUP nginx

Putting It Together

A typical admin flow: spot a CPU hog in top, lower its priority with renice instead of killing it, and only escalate to kill -9 if it misbehaves.

renice -n 15 -p 8899 || kill -TERM 8899

Quick Check

Which niceness value gives a process the highest CPU priority?

Recap

You learned to fine-tune process behavior:

  • nice -n N cmd starts at a chosen priority
  • renice changes priority of running PIDs
  • Negative niceness needs root
  • Signals like SIGTERM, SIGHUP, SIGSTOP/SIGCONT control processes without killing them
免费开始

用 AI 导师学习 Linux Command Line Mastery — 免费

在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。

课程
12
课程
48

常见问题解答

「使用 nice、renice 与信号管理进程优先级」课时是免费的吗?

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

「使用 nice、renice 与信号管理进程优先级」这节课中我会学到什么?

使用 nice 和 renice 控制进程获得的 CPU 资源,并学习信号如何让您与运行中的进程通信,而不仅仅是终止它们。 你通过在浏览器中直接运行的动手代码来练习 Linux Command Line Mastery,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

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

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

「使用 nice、renice 与信号管理进程优先级」课时需要多长时间?

大多数 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