Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
bashの組み込みコマンド
Satoru Takeuchi
PRO
June 24, 2022
Technology
1
27
bashの組み込みコマンド
以下動画のテキストです
https://youtu.be/6oVvcnwRUa0
Satoru Takeuchi
PRO
June 24, 2022
Tweet
Share
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
THE FIRST CODE: FizzBuzz
sat
PRO
0
15
sysfs
sat
PRO
0
18
RAID
sat
PRO
1
16
Linuxカーネルのソースについての小ネタ集
sat
PRO
1
64
bashの組み込みコマンドの自作
sat
PRO
0
19
5分で作る分散ストレージ
sat
PRO
1
99
timeコマンド
sat
PRO
0
21
KubeCon EU 2022 Ceph Intro & Rook Deep Dive
sat
PRO
0
39
YAMLを書くだけで構築できる分散ストレージ
sat
PRO
0
280
Other Decks in Technology
See All in Technology
増田亨さんによる 「設計の考え方とやり方」勉強会オープニング
tsuyok
0
200
聊聊 Cgo 的二三事
david74chou
0
330
ふりかえりの技術 / retrospectives
soudai
3
160
EKS AnywhereとIAM Anywhereを組み合わせてみた
regmarmcem
0
270
データ分析のためのAWS Well-Architected -Data Analytics Lens-
maru1981
0
230
ReverseETLでユーザーに価値を届ける基盤を実現した話
hakky
0
340
森林情報のオープンデータと QGISでの利用
kou_kita
0
150
年700万円損するサーバレスの 認可システムをご紹介します!!
higuuu
3
330
Trusted Web プロトタイプ
finengine
0
320
Amplifyで Webアプリケーションの 堅固な土台をサクッと構築する方法
kawasakiteruo
0
210
漫画で使えそうな背景画像をblenderを使って作ってみた!
nokonoko1203
1
260
ジョブ管理システムをAWS Step Functionsに移行する時の勘所
non97
0
490
Featured
See All Featured
Navigating Team Friction
lara
175
11k
Creatively Recalculating Your Daily Design Routine
revolveconf
207
10k
Three Pipe Problems
jasonvnalue
89
8.7k
The Pragmatic Product Professional
lauravandoore
19
3.1k
Docker and Python
trallard
27
1.6k
What the flash - Photography Introduction
edds
62
10k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
6
570
The Art of Programming - Codeland 2020
erikaheidi
32
11k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
15
980
Bash Introduction
62gerente
598
210k
The Web Native Designer (August 2011)
paulrobertlloyd
75
2k
Typedesign – Prime Four
hannesfritz
34
1.4k
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には組み込みコマンドが存在する • 組み込みコマンドにする目的はさまざま ◦ 高速化 ◦ そもそも実行ファイルでは実現できない