Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
プロセスの生成 exec編
Search
Satoru Takeuchi
PRO
December 29, 2024
Technology
98
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
プロセスの生成 exec編
以下動画のテキストです。
https://youtu.be/0qsIC-lpP8E
Satoru Takeuchi
PRO
December 29, 2024
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
80
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
110
あなたの知らないバージョン命名規則
sat
PRO
3
930
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
74
Machine Check Exception
sat
PRO
2
72
バイナリダンプの模様を読む
sat
PRO
0
120
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
110
114-ファイルのshallow_copy.pdf
sat
PRO
2
63
113-Btrfsのスナップショット.pdf
sat
PRO
0
48
Other Decks in Technology
See All in Technology
Kiro Crewで「みのるん式」仕事術やってみた
minorun365
PRO
3
990
局所最適は悪ではない。壊れているのは指標です。量と質を同時に見る先行指標の設計
recruitengineers
PRO
2
230
古い指輪から広がった JAVA コミュニティ とのつながり
yamad
0
130
AI駆動で「他アプリの音を加工できる」アプリを作った
satomasahiro2005
0
190
Classmethod Company Deck
satoshi7
1
800
ストレスなくAIと付き合いたい!こんなときどうしてる?
namiki64
4
660
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
220
sue445's proposals 2026
sue445
0
120
DevelopersIO 2026 Tokyo 現時点の衛星通信サービスの現状を整理してみる
maroon1st
0
110
[EMNLP26] RIGEL: Self-Distilled Score Adaptation for Image and Video Captioning Evaluation
keio_smilab
PRO
0
110
顧客価値を追いかけたら、プライシングにたどり着いた
sansantech
PRO
2
350
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
170
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
540
Git: the NoSQL Database
bkeepers
PRO
433
67k
Product Roadmaps are Hard
iamctodd
55
13k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
310
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
320
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Transcript
プロセスの生成 exec編 Dec. 29th, 2024 Satoru Takeuchi X: satoru_takeuchi 1
exec関数とは • Linuxで新しいプログラムを実行する関数 • forkと似て非なるもの ◦ fork: プロセスを複製して新しいプロセスを作成する ◦ exec:
同じプロセス上で新しいプログラムを実行する 2
exec(): CPU上で動作する処理の観点 1. CPU上で動くプロセスがexec()を呼ぶ 2. exec()後にプロセスはexecで指定したプログラムを実行する 3 CPU exec()呼び出し exec()から復帰
プロセス (プログラムA) カーネル プロセス (プログラムB)
exec: 物理メモリの観点 4 プロセスの メモリ (プログラムA) (1) exec()呼び出し時 カーネルの メモリ
プロセスの メモリ (プログラムA) カーネルの メモリ プロセスの メモリ (プログラムB) カーネルの メモリ CPU上で 実行中のコード (2) カーネルによるexec()の処理 (3) exec()復帰後 CPU上で 実行中のコード CPU上で 実行中のコード (プログラムBの エントリポイント) プロセスの メモリ (プログラムB) 新規割り当て 後で解放
コード #!/usr/bin/python3 import os print(f"プログラムA(exec前): pid={os.getpid()}") os.execve("./b.py", ["b.py"],{}) print("この業は実行されないはず") 5
プログラムA(a.py) プログラムB(b.py) #!/usr/bin/python3 import os print(f"プログラムB(exec後): pid={os.getpid()}")
実行結果 • プログラムAをするとexec呼び出しによってプログラムBが実行される • execの後のprint()文は実行されない • execによってpidは変わらない 6 $ ./a.py
プログラムA(exec前): pid=135225 プログラムB(exec後): pid=135225
まとめ • 新しいプログラムを実行する際はexec関数を呼び出す • forkと似て非なるもの ◦ fork: プロセスを複製して新しいプロセスを作成する ◦ exec:
同じプロセス上で新しいプログラムを実行する • 📝 ひとくちにexecといっても“man 3 exec”を見るとexecl,execlp…など似たような ものがたくさんあるが、全部ただの変種なので気にしなくていい 7