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
250
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
bashの組み込みコマンド
以下動画のテキストです
https://youtu.be/6oVvcnwRUa0
Satoru Takeuchi
PRO
June 24, 2022
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
43
Machine Check Exception
sat
PRO
2
51
バイナリダンプの模様を読む
sat
PRO
0
71
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
58
114-ファイルのshallow_copy.pdf
sat
PRO
2
43
113-Btrfsのスナップショット.pdf
sat
PRO
0
23
システム強制終了時にファイルシステムの整合性を保つ~ コピーオンライト編 ~
sat
PRO
0
63
システム強制終了時に ファイルシステムの整合性を保つ ~ ジャーナリング編 ~
sat
PRO
2
69
ファイルシステムの整合性を回復するfsck
sat
PRO
1
75
Other Decks in Technology
See All in Technology
Issue設計から始める仕様駆動開発 / 20260731 Mizuki Hirata
shift_evolve
PRO
1
150
Flutterをカメラで動かしたかった話
sony
1
130
ブラウザ研修 2026
recruitengineers
PRO
5
800
OSPN.JPバージョンアップ作業進捗のご報告 / 20260801-osc26kyoto
akkiesoft
0
420
【CEDEC2026】『ウマ娘 プリティーダービー』 英語版のキャラクターの方言や口調をローカライズするための創造的アプローチ
cygames
PRO
1
200
AWS ネットワーク構築でハマった(ハマりかけた) 5選とそこから得た教訓
nagisa53
4
200
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
220
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.2k
グローバル基準のSREは、運用現場でどう機能したか:成熟度アセスメントの実践 / SRE NEXT 2026
sorawatanabe
0
140
第3回しろおびセキュリティスポンサーセッション
log0417
0
160
【CEDEC2026】『GRANBLUE FANTASY: Relink - Endless Ragnarok』のバトル制作事例 ~最高のキャラゲーを目指して~
cygames
PRO
0
230
Invisible to AI? Making TYPO3 Sites Quotable by AI Search Systems
wolfgangwagner
0
170
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
Product Roadmaps are Hard
iamctodd
55
12k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
330
Test your architecture with Archunit
thirion
1
2.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
56k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
400
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.2k
30 Presentation Tips
portentint
PRO
1
360
Building a Scalable Design System with Sketch
lauravandoore
463
34k
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には組み込みコマンドが存在する • 組み込みコマンドにする目的はさまざま ◦ 高速化 ◦ そもそも実行ファイルでは実現できない