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?

ユーザモード、カーネルモードを見る

Posted at
root@****:********# taskset -c 0 python3 hello.py &
[1] 2682
root@****:********# sar -P 0 1 1
Linux 5.15.0-100-generic (********) 	2024年05月14日 	_x86_64_	(1 CPU)

10時44分10秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
10時44分11秒       0    100.00      0.00      0.00      0.00      0.00      0.00
平均値:        0    100.00      0.00      0.00      0.00      0.00      0.00
root@****:********# kill 2682

プロセスがユーザモードで実行しているとき、「プロセスはユーザランド(あるいはユーザ空間)で実行しているということもあります。
...
プロセスはユーザモードで動作するため、デバイスにアクセスできません。

出典

気づき

userが100%ということは期間内100%ユーザモードだったということか

root@****:********# vim hello.py
[1]+  Terminated              taskset -c 0 python3 hello.py
root@****:********# taskset -c 0 python3 hello.py &
[1] 2697
root@****:********# sar -P 0 1 1
Linux 5.15.0-100-generic (********) 	2024年05月14日 	_x86_64_	(1 CPU)

10時49分36秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
10時49分37秒       0     69.05      0.00     30.95      0.00      0.00      0.00
平均値:        0     69.05      0.00     30.95      0.00      0.00      0.00
root@****:********# kill 2697

このhello.pyは無限にシステムコールするようになってます

カーネルに処理を依頼するためにシステムコールを発行すると、CPUにおいて例外というイベントが発生します。
これをきっかけとして、CPUのモードがユーザモードからカーネルモードに遷移し、依頼内容に応じたカーネルの処理が動き始めます。カーネル内のシステムコール処理が終了すれば、再びユーザモードに戻ってプロセスの動作を継続します。

出典

%sys

プロセッサがシステムモードになっている時間の割合が表示される

出典

# 気づき
この期間ユーザモードが約70%、カーネルモードが約30%動いていたことになる。

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?