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
なるほどUNIXプロセス14_15章
Search
indigolain
May 07, 2016
Programming
0
120
なるほどUNIXプロセス14_15章
なるほどUNIXプロセス14_15章
http://tatsu-zine.com/books/naruhounix
indigolain
May 07, 2016
Tweet
Share
More Decks by indigolain
See All by indigolain
スタディサプリにおける TypeScript 活用事例と今後の展望 / jsconf-jp-2021
indigolain
3
4k
フロントエンドチーム立ち上げで学んだTips / What I learned from organizing the new frontend team
indigolain
0
740
Persisted-queryをやってみた
indigolain
1
1.1k
TEC DEPT 201610 Catal Engineer5期生募集
indigolain
0
450
なるほどUNIXプロセス10~11章
indigolain
0
120
なるほどUNIXプロセス4~5章
indigolain
0
150
Other Decks in Programming
See All in Programming
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Jakarta EE meets AI
ivargrimstad
0
600
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
CSC509 Lecture 12
javiergs
PRO
0
160
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Why Our Code Smells
bkeepers
PRO
334
57k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Documentation Writing (for coders)
carmenintech
65
4.4k
Adopting Sorbet at Scale
ufuk
73
9.1k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
A designer walks into a library…
pauljervisheath
203
24k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Unsuck your backbone
ammeep
668
57k
Transcript
14~15ষ ͳΔ΄ͲUNIXϓϩηε
ςΩετ ୈ̍̐ষϓϩηεͯΔ ▸ ࢠकΓ ▸ Process.waitͱͦͷҰ ▸ Process.wait2ΛͬͯΓͱΓ͢Δ ▸ ಛఆͷࢠϓϩηεΛͭ
▸ ڝ߹ঢ়ଶ ▸ ࣮༻ྫ ▸ ͜ͷষͰѻͬͨγεςϜίʔϧ
ςΩετ ࢠकΓ ▸ ͜Ε·Ͱѻ͖ͬͯͨfork(2)ͷྫʮܸͪͬͺͳ͠(fire and forget)ʯ ▸ ࢠϓϩηεଆͰ͋ΔॲཧΛͤͭͭ͞ɺඇಉظͰϓϩηε ͰผͷॲཧΛ͢Δ߹ʹྑ͍ ▸
͜ͷ߹Ҏ֎ࢠϓϩηεΛཧͯ͘͠ΕΔΈ͕ඞཁ ▸ ͜Ε͕Process.wait
ςΩετ ࢠकΓ ▸ process_wait_example.rb ▸ Process.waitࢠϓϩηεͷͲΕ͔͕̍ͭऴྃ͢Δ·Ͱͷ ؒɺϓϩηεΛϒϩοΫͯͭ͠ɻ
ςΩετ PROCESS.WAITͱͦͷҰ ▸ ̍ͭҎ্ͷϓϩηεΛࢹ͢Δඞཁ͕͋Δ߹ɺͲͷࢠϓϩ ηε͕ऴ͔ྃͨ͠ΛΔඞཁ͕͋Δ ▸ Process.waitͷΓऴྃͨ͠ࢠϓϩηεͷpidΛฦ͢ͷ Ͱɺ͜ΕΛ͏ ▸ process_wait_pid_example.rb
ςΩετ PROCESS.WAIT2ΛͬͯΓͱΓ͢Δ ▸ Process.waitʹProcess.wait2ͱ͍͏ੰ͕͋Δ ▸ Process.wait2pidͱऴྃεςʔλεΛฦΓͱͯ͠ฦ͢ ▸ ऴྃεςʔλεऴྃίʔυʹΑΔϓϩηεಉ࢜ͷ௨৴खஈͱ͠ ͯΘΕΔ ▸
Process.wait2͕ฦ͢ऴྃεςʔλεProcess::StatusΫϥεͷΠ ϯελϯε ▸ process_wait2_example.rb
ςΩετ ಛఆͷࢠϓϩηεΛͭ ▸ Process.watpidͱProcess.waitpid2 ▸ ऴྃΛͭͷҙͷࢠϓϩηεͰͳ͘ɺࢦఆͨ͠ࢠϓϩηε ▸ ऴྃΛͭࢠϓϩηεpidͰࢦఆ͢Δ ▸ ݩಉؔ͡Λࢦ͍ͯ͠Δ
▸ Process.waitʹpidΛ͢ ▸ Process.waitpidʹ-1Λ͢
ςΩετ ڝ߹ঢ়ଶ ▸ Χʔωϧऴྃͨ͠ϓϩηεΛΩϡʔʹೖΕΔ ▸ ऴྃΛͭࢠϓϩηε͕1ͭແ͍ঢ়ଶͰProcess.waitΛݺ ͼग़͢ͱErrno::ECHILDྫ֎͕ૹग़͞ΕΔ ▸ no_processwait.rb
ςΩετ ࣮༻ྫ ▸ ࢠϓϩηεΛ׆༻͢Δύλʔϯ ▸ ༻ҙͨ͠1ͭͷϓϩηε͔ΒฒߦॲཧͷͨΊʹෳͷࢠϓϩηεΛੜ ͯ͠ɺͦͷޙࢠϓϩηεͷ໘ΛΈΔͱ͍͏ܗࣜ ▸ Ԡ/ऴྃ࣌ͷޙ࢝ͳͲ ▸
Unicorn͕͜ͷύλʔϯΛ࠾༻͍ͯ͠Δ ▸ αʔόىಈ࣌ʹϫʔΧʔϓϩηεΛ͍ͭ͘͏͔Λࢦఆ͢Δ ▸ Unicornʹؔͯ͠2ʮUnicornͷϫʔΧʔϓϩηεͷཧʯࢀর
ςΩετ ͜ͷষͰѻͬͨγεςϜίʔϧ ▸ Process.waitܥwaitpid(2)ʹରԠ͍ͯ͠Δ
ςΩετ ୈ̍̑ষκϯϏϓϩηε ▸ Ռใ৸ͯͯ ▸ κϯϏͲΜͳ෩ʹΈ͑Δͷ͔ʁ ▸ ࣮༻ྫ ▸ ͜ͷষͰѻͬͨγεςϜίʔϧ
ςΩετ Ռใ৸ͯͯ ▸ Χʔωϧϓϩηε͕Process.waitΛͬͯͦͷใΛཁٻ͢Δ·Ͱ ऴྃͨ͠ࢠϓϩηεͷใΛͣͬͱ࣋ͪଓ͚Δ ▸ ΧʔωϧͷϦιʔεͷແବ͍ʹͭͳ͕ͬͯ͠·͏ ▸ Process.waitΛͬͯࢠϓϩηεͷऴྃΛͨͳ͍߹ɺࢠϓϩηεΛ σλονͤͶͳΒͳ͍
▸ Process.detachpidͰࢦఆ͞ΕͨࢠϓϩηεͷऴྃΛͭεϨουΛ ੜ͢Δ ▸ detach_example.rb
ςΩετ κϯϏͱͲͷΑ͏ʹݟ͑Δͷ͔ʁ ▸ zombie_process_example.rb ▸ ps -ho pid, state -p
[κϯϏʹͳͬͨϓϩηεͷpid]
ςΩετ ࣮༻ྫ ▸ ϓϩηεʹͨΕͣʹࢮΜͰ͠·ͬͨࢠϓϩηεྫ֎ͳ͘κϯϏϓ ϩηεʹͳΔ ▸ ϓϩηε͕κϯϏϓϩηεͷऴྃεςʔλεΛऔಘ͢Εɺใ ফ͑Δ ▸ ॲཧΛόοΫάϥϯυͰ࣮ߦ͢Δඞཁ͕͋ΔόΠΠʹɺઐ༻ͷόο
ΫάϥϯυΩϡʔΠϯάγεςϜ͕ΘΕΔ͜ͱ͕ଟ͍ ▸ spawnlingͱ͍͏gemΛ͑ɺϓϩηεεϨουΛѻ͏૯শతͳ APIΛఏڙ͢Δ͜ͱʹՃ͑ͯɺʮܸͪͬ์͠ʯͰੜͨ͠ࢠϓϩηεΛ Ͱλονͯ͘͠ΕΔ
ςΩετ ͜ͷষͰѻͬͨγεςϜίʔϧ ▸ Process.detachʹ͋ͨΔγεςϜίʔϧଘࡏ͠ͳ͍ ▸ RubyͰεϨουͱProcess.waitΛ࣮ͬͯݱ͍ͯ͠Δ