0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux] プロセス管理_コマンド_ps, top, kill, jobs, &, fg, bg, free, uptime, uname, watch

Last updated at Posted at 2025-01-29

システム、プログラム、プロセス、ジョブの関係

単位 説明
システム Linuxカーネルとユーザー空間のソフトウェア(シェル、デーモン、サービスなど)を含む全体
プログラム 実行前(実行可能)のコードやコマンド
プロセス プログラムがカーネルによってメモリ上にロードされ、CPUで実行されている状態
ジョブ シェルで起動されたバックグラウンドまたはフォアグラウンドのプロセスの単位

プロセスの監視

psコマンド

$ ps [オプション]
オプション 由来 説明
default process status - 実行中のプロセスの情報を表示
a all - すべてのプロセス(端末に関連しないプロセスも含む)を表示
f forest - プロセスの親子関係をツリー状に表示(psで親子関係を視覚的に表示)
u user - 指定したユーザーのプロセスのみを表示
x executing - 端末に関連しないプロセスも表示
-aux all, user, executing - すべてのプロセスを詳細表示(-e -f -x の組み合わせに近い)
-axf all, executing, full-format - すべてのプロセスを詳細表示し、親子関係もツリー状に表示
-e every - すべてのプロセスを表示
-f full-format - 詳細な情報を含む完全なフォーマットで表示(親子関係も表示)

pstreeコマンド

$ pstree [オプション]
オプション 由来 説明
default process tree - プロセスをツリー状に表示

topコマンド

$ top [オプション]
オプション 由来 説明
default table of processe - システムのプロセスとリソース使用状況をリアルタイムで表示
-d delay - 更新間隔を秒単位で指定(例:top -d 3 で3秒ごとに更新)
-u user - 指定したユーザーのプロセスのみを表示
-p process - 指定したPIDのプロセス情報のみを表示
-n number - 指定回数の更新後に自動終了(例:top -n 5 で5回更新後に終了)
-b batch - バッチモード(対話なし)で出力

プロセスの終了

killコマンド
$ kill -[シグナル名まらはシグナルID] PID
$ kill -s [シグナル名まらはシグナルID] PID
$ kill -SIGシグナル名 PID
シグナル名 シグナルID 動作
HUP 1 ハングアップ
INT 2 キーボードからの割り込み or Ctrl+C
KILL 9 強制終了
TERM 15 終了(デフォルト)

ジョブの管理

&

# updatedb &

fgコマンド

# fg ジョブ番号

bgコマンド

# bg ジョブ番号

メモリの利用状況や空き状況の確認

システムの稼働時間や平均負荷の確認

システムのアーキテクチャの確認

コマンドの自動実行

watchコマンド

$ watch [オプション] 指定コマンド
オプション 由来 説明
default watch - 指定コマンドを一定間隔で繰り返し実行し、出力をリアルタイムで更新
-n 秒数 interval - 更新間隔を秒単位で指定(デフォルトは2秒)
-d difference - 前回の出力と異なる部分をハイライト表示
-t no title - 画面上部のヘッダー(更新間隔やコマンド名など)を非表示
-b beep - 実行したコマンドが0以外の終了ステータスを返した場合にビープ音を鳴らす
-p precise - 指定した間隔で正確に更新を実施(処理時間の影響を考慮)
-e exit - 実行したコマンドが0以外の終了ステータスを返した場合にwatchを終了

Ping-t

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?