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
bashの組み込みコマンド
Search
Satoru Takeuchi
PRO
June 24, 2022
Technology
1
140
bashの組み込みコマンド
以下動画のテキストです
https://youtu.be/6oVvcnwRUa0
Satoru Takeuchi
PRO
June 24, 2022
Tweet
Share
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
Linux環境のCPU上で10ミリ秒間に起こること
sat
PRO
3
73
HDDへのアクセス速度は位置によって変わる!??
sat
PRO
4
33
ボリュームマネージャLVM
sat
PRO
2
74
Best Practices of Production-Grade Rook/Ceph Cluster
sat
PRO
1
1.7k
OSSへの貢献をはじめたきっかけ、貢献で得たもの、やりたい人へのアドバイス(改)
sat
PRO
4
120
device mapperによるディスクI/O障害のエミュレーション 既存ターゲット編
sat
PRO
0
100
分散ストレージCephのデータ破壊検知修復機能は本当に動作するのか
sat
PRO
0
42
ディスクI/O障害のエミュレーション カーネルモジュール自作編
sat
PRO
0
39
分散ストレージはすごいぞ
sat
PRO
2
2.5k
Other Decks in Technology
See All in Technology
10分でわかるfreeeのQA
freee
0
230
暗黙知を集積するプラットフォーム : 「健常者エミュレータ事例集」の取り組み
sora32127
1
160
あらゆる商品を扱う商品データベースを再設計した話 / product db re-architecture
rince
8
3.7k
Kubeflow Pipelines v2 で変わる機械学習パイプライン開発
asei
4
340
オブジェクトのおしゃべり大失敗 メッセージングアンチパターン集 / messaging anti-pattern collection
ytake
0
330
Vos logs méritent mieux que la config par défaut
lyrixx
2
340
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
7
100k
業務で使えるかもしれない…!?GitHub Actions の Tips 集 / CI/CD Test Night #7
ponkio_o
PRO
24
7k
Getting started with controlling LEGO using Swift
hcrane
0
130
期待しすぎずに取り組む両面 TypeScript
shozawa
2
300
Introduction to Jetpack Compose
pohjus
1
110
TypeScript Quiz (Encraft #12 Frontend Quiz Night)
uhyo
5
440
Featured
See All Featured
Fireside Chat
paigeccino
19
2.6k
No one is an island. Learnings from fostering a developers community.
thoeni
14
2k
What's in a price? How to price your products and services
michaelherold
236
11k
Reflections from 52 weeks, 52 projects
jeffersonlam
343
19k
GraphQLの誤解/rethinking-graphql
sonatard
48
9.1k
Scaling GitHub
holman
456
140k
How STYLIGHT went responsive
nonsquared
92
4.7k
Done Done
chrislema
178
15k
Become a Pro
speakerdeck
PRO
8
4.4k
Principles of Awesome APIs and How to Build Them.
keavy
119
16k
Agile that works and the tools we love
rasmusluckow
323
20k
Pencils Down: Stop Designing & Start Developing
hursman
115
11k
Transcript
bashの組み込みコマンド Jun. 24th, 2022 Satoru Takeuchi twitter: satoru_takeuchi
bashの組み込みコマンドとは • bash上で”help”を実行すると出てくるコマンドたち • 新規プロセスを生成せずにbash自身が処理 • 種類 ◦ “if”や”for”などの制御構文 ◦
echoなどの頻出コマンド ◦ waitやcdなどの組み込みコマンドでなければ実現できないもの
echoはなぜ組み込みコマンドなのか • bashスクリプト内で頻出するので高速なほうが都合がよい ◦ /bin/echoを実行するとbashを親とした新規プロセスの生成が必要 ◦ 組み込みコマンドなら新規プロセスの生成が不要 • 実験: 組み込みコマンド(echo)
vs 実行ファイル(/bin/echo) ◦ bashスクリプト内で10000回実行したときの所要時間を比較 • 📝 実はtimeも組み込みコマンド ◦ しかも組み込みコマンドと実行ファイルで微妙にデフォルト出力が違う
waitはなぜ組み込みコマンドなのか • “wait”は子プロセスの終了を親が待つシステムコール ◦ 子ではないプロセスの終了は待てない • “man 2 wait”より抜粋 ◦
All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed.
cdはなぜ組み込みコマンドなのか • “cd”は内部的に”chdir”システムコールを呼ぶ • “chdir”はシステムコールを呼んだプロセスのワーキングディレクトリを変更 • “man 2 chdir”より抜粋 ◦
chdir() changes the current working directory of the calling process to the directory specified in path. • 親プロセス(bash)には影響を及ぼさない
まとめ • bashには組み込みコマンドが存在する • 組み込みコマンドにする目的はさまざま ◦ 高速化 ◦ そもそも実行ファイルでは実現できない