0Pricing
Linux Command Line Mastery · レッスン

nice、renice、シグナルでプロセス優先度を扱う

nice と renice を使ってプロセスに割り当てる CPU の量を制御し、単にプロセスを終了するだけでなく、シグナルで実行中のプロセスと通信する方法を学びます。

「nice、renice、シグナルでプロセス優先度を扱う」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応の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

よくある質問

「nice、renice、シグナルでプロセス優先度を扱う」レッスンは無料ですか?

はい。「nice、renice、シグナルでプロセス優先度を扱う」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。

「nice、renice、シグナルでプロセス優先度を扱う」で何を学びますか?

nice と renice を使ってプロセスに割り当てる CPU の量を制御し、単にプロセスを終了するだけでなく、シグナルで実行中のプロセスと通信する方法を学びます。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応の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に戻る