LoginSignup
2
1

More than 1 year has passed since last update.

ハンズオン Linuxのしくみ

Last updated at Posted at 2023-02-13

Linuxから目を背け続けていたのですが、お仕事で必要になったってしまったので、
うさぎのアイコンの方が著者の "Linuxのしくみ" を試して理解しようと思います。

環境

作業用のメインPCのTeratermから、ミニPCのUbuntuにアクセスします。
・ミニPC: 8GB DDR, 128G SSD, Intel N5095
image.png

詳細手順は下記。
https://qiita.com/nekokane/items/610294ce18e9ae802582

参考文献

[1]「Linuxのしくみ 増補改訂版」の実験コード
https://github.com/satoru-takeuchi/linux-in-practice-2nd

事前準備

0.1. Teratermでログイン

image.png

0.1 実験プログラム実行環境の作成 [1] p xi

パッケージのインストールと、ユーザーの追加。
https://github.com/satoru-takeuchi/linux-in-practice-2nd

sudo apt update && ・・・

1. Linuxの概要

・ユーザーモード=ユーザーランド=ユーザー空間
 カーネルさんが、ストレージアクセスとか制御してくれるので、安心。
・システムコール
 ユーザモードのプロセスから、カーネルに処理を依頼。
・システムコールを見る
 https://github.com/satoru-takeuchi/linux-in-practice-2nd/blob/main/01-operating-system-overview/hello.go

/*---------------------
hello.goをgithubからローカルにコピーする方法が分からない。
・GitHubからプログラムをダウンロード・インストール
 https://rnakato.hatenablog.jp/entry/2018/08/04/151041
 ・Code -> Local Clone -> コピー で良さそう。
image.png

git clone https://github.com/satoru-takeuchi/linux-in-practice-2nd.git

---------------------*/

01-02 hello.py

・hello.goがあるフォルダに移動"cd"する。

$ cd linux-in-practice-2nd/
$ cd 01-operating-system-overview/

・ hello.goをビルドして、実行。

$ go build hello.go
$ ./hello

・straceで実行して、logを表示

$ strace -o hello.log ./hello
$ cat hello.log

・hello world 改行が表示されるようにシステムコールしているっぽい。

write(1, "hello world\n", 12)           = 12

// 2023年2月14日 P6 今日はここまで・・・

01-02 hello.py

hello .pyは、~/linux-in-practice-2nd/01-operating-system-overview 配下にある。

kaneb1a@beelink01a:~/linux-in-practice-2nd/01-operating-system-overview$ ls
hello  hello.go  hello.log  hello.py  inf-loop.py  pause.c  syscall-inf-loop.py

helo.pyの実行をトレース。hello waorldを表示するのは、goでもpyでも、
write(1 っぽい。

strace -o hello.py.log ./hello.py
cat ./hello.py
~
write(1, "hello world\n", 12)           = 12
~

sarコマンド CPUを使ってる時間

sar -P 0 1 1

01-03 inf-loop.py

CPU 0でループ刺せて、sarコマンドで、CPU使用状態を見る。

taskset -c 0 ./inf-loop.py &
sar -P 0 1 1
08:17:18 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
08:17:19 PM       0    100.00      0.00      0.00      0.00      0.00      0.00

無事に、userによるCPU使用が100になった!
// 2/19 P9 まで

2
1
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
2
1