Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
/proc を見てみる
Search
Osumi, Yusuke
June 20, 2020
Technology
390
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
/proc を見てみる
「新しいLinuxの教科書」を読む会 オンライン #2
での発表資料です。
https://linuxbook.connpass.com/event/178366/
Osumi, Yusuke
June 20, 2020
More Decks by Osumi, Yusuke
See All by Osumi, Yusuke
本の紹介の補足
ozuma
1
420
gitサービス3兄弟
ozuma
0
420
簡体字は楽
ozuma
0
500
ソフトウェアは固定資産
ozuma
0
450
ASCIIコードの小話
ozuma
0
470
今いるディレクトリを消すとどうなる
ozuma
1
420
名前付きパイプ FIFO
ozuma
0
580
文章、作文技法 リモートワーク
ozuma
1
940
CentOSの今後のリリース(簡易説明)
ozuma
0
430
Other Decks in Technology
See All in Technology
MulticaとPi Coding Agentで、小規模OSSを30本同時運用した流れ
eiei114
0
130
AIのためのEthernet技術動向 (SerDes)
markunet
1
200
『三匹の子ぶた』から学ぶネットワークセキュリティの昔と今 / Network Security: Then and Now Through the Lens of The Three Little Pigs
nttcom
1
6.2k
なぜ Temporal の大小比較には compare しかないのか / Why Does Temporal Only Have compare() for Comparisons
kazukihayase
1
150
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
240
FDEの心得
noriakioji
5
6.3k
認知負荷をGemini で溶かす — GKE 基盤「Orbit」における AI エージェントの実践
sansantech
PRO
1
320
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
JavaScript 研修 (2026)
recruitengineers
PRO
2
610
社内の7割が使うデータ基盤を、 データチーム2人で回すためにやったこと
koh_yoshi
4
1.4k
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
20k
私がブラウザを自作したくなった理由
supurazako
1
260
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
400
Building the Perfect Custom Keyboard
takai
2
840
Scaling GitHub
holman
464
140k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Building an army of robots
kneath
306
46k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
How to train your dragon (web standard)
notwaldorf
97
6.8k
It's Worth the Effort
3n
188
29k
Making Projects Easy
brettharned
120
6.7k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Transcript
/proc を見てみる @ozuma5119 1 「新しいLinuxの教科書」を読む会 オンライン #2 2020/06/20
2
3
4 $ man proc
5 https://linuxjm.osdn.jp/html/LDP_man-pages/man5/proc.5.html
6 https://linuxjm.osdn.jp/html/LDP_man-pages/man5/proc.5.html pseudo-file system : 擬似ファイルシステム
まずは見てみましょう 7
8 数字のディレクトリたくさん + それっぽいファイル名たくさん + それっぽいディレクトリ名がいくつか
9 $ cat /proc/meminfo MemTotal: 16294336 kB MemFree: 15851072 kB
MemAvailable: 15843672 kB Buffers: 25336 kB Cached: 204780 kB SwapCached: 0 kB Active: 164016 kB Inactive: 100876 kB Active(anon): 35612 kB Inactive(anon): 444 kB Active(file): 128404 kB Inactive(file): 100432 kB Unevictable: 16 kB Mlocked: 0 kB SwapTotal: 16666620 kB SwapFree: 16666620 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 34564 kB Mapped: 63636 kB Shmem: 1284 kB KReclaimable: 32704 kB Slab: 81764 kB SReclaimable: 32704 kB SUnreclaim: 49060 kB KernelStack: 2548 kB PageTables: 1304 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 24813788 kB Committed_AS: 261736 kB VmallocTotal: 34359738367 kB VmallocUsed: 41272 kB VmallocChunk: 0 kB Percpu: 3552 kB HardwareCorrupted: 0 kB AnonHugePages: 2048 kB ShmemHugePages: 0 kB
10 $ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel
cpu family : 6 model : 58 model name : Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz stepping : 9 microcode : 0x21 cpu MHz : 1600.787 cache size : 8192 KB physical id: 0 siblings : 8 core id : 0 cpu cores : 4 apicid : 0 initial apicid : 0 fpu : yes ....(省略).... cache_alignment: 64 address sizes : 36 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz stepping : 9 microcode : 0x21 cpu MHz : 1600.503 cache size : 8192 KB physical id: 0 siblings : 8 core id : 1 cpu cores : 4 ....(省略)....
/proc ディレクトリの擬似ファイル (イメージ) 11 メモリ カーネル メモリ上に 展開 窓のような疑似 ファイル(
/proc ) /proc ファイルを通して、カーネルの現在のプロ セス管理状態や各種情報の取得 (一部は書き込み=設定変更も可能)
計算して uptime コマンドと比べてみよう 12 $ cat /proc/uptime 1313352.37 1311195.34 $
$ uptime 02:49:25 up 15 days, 4:49, 3 users, load average: 0.00, 0.01, 0.05 1313352秒 ≒ 21889分 ≒ 364時間 ≒ 15日ちょっと
13 数字のディレクトリはプロセスごとの proc ファイル。 プロセスIDに対応したディレクトリになっている
psコマンドと比べてみよう 14 # ps ww -p 20446 PID TTY STAT
TIME COMMAND 20446 ? Ss 0:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic" # # cat -v /proc/20446/cmdline /usr/bin/ssh-agent^@/bin/sh^@-c^@exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"^@ ※ ^@ =0x00, ゼロ終端 ※他人のプロセス情報はrootで無いとあまり見られない
procfs系のコマンドは、procから拾って組み立てる (ps, top, uptime, vmstat... 等) 15 [root@cent7 ~]# strace
ps execve("/bin/ps", ["ps"], 0x7ffc3e00eb10 /* 18 vars */) = 0 ....(省略)... stat("/proc/1", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0 open("/proc/1/stat", O_RDONLY) = 6 read(6, "1 (systemd) S 0 1 1 0 -1 4202752"..., 1024) = 375 close(6) = 0 open("/proc/1/status", O_RDONLY) = 6 read(6, "Name:\tsystemd\nUmask:\t0000\nState:"..., 1024) = 1024 read(6, "0,00000000,00000000,00000000,000"..., 1024) = 178 close(6) = 0 stat("/proc/2", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0 open("/proc/2/stat", O_RDONLY) = 6 read(6, "2 (kthreadd) S 0 0 0 0 -1 213817"..., 2048) = 169 close(6) = 0 ....(省略)...
書き込む例:一時的にカーネルパラメタをいじる 16 # cat /proc/sys/net/ipv4/icmp_echo_ignore_all ← pingの応答を返すか? 0 # ping
localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.028 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.029 ms ...(省略)... # # echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all ← pingを無視する # ping localhost PING localhost (127.0.0.1) 56(84) bytes of data. ^C --- localhost ping statistics --- 8 packets transmitted, 0 received, 100% packet loss, time 6999ms 永続的には /etc/sysctl.conf: net.ipv4.icmp_echo_ignore_all=1
例:わざとシステムをクラッシュ(Windowsで言うブルースクリーン) 17 # echo 1 > /proc/sys/kernel/sysrq ← sysrqを有効化 #
echo c > /proc/sysrq-trigger ← カーネルにSystem Crash命令を送る
参考文献 • Man page of PROC ◦ https://linuxjm.osdn.jp/html/LDP_man-pages/man5/proc.5.html • Linux
procfs 徹底入門 ◦ https://www.kimullaa.com/entry/2019/12/15/075138 • Wikipedia: procfs ◦ https://ja.wikipedia.org/wiki/Procfs • RedHat Enterprise Linux 6: 導入ガイド 付録E PROC ファイルシステム ◦ https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/deployment_guide/ch-proc • その5: procfs (Satoru Takeuchi) ◦ https://www.youtube.com/watch?v=y0N4TmNRmQg 18