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
110
なるほどUNIXプロセス4~5章
indigolain
0
150
Other Decks in Programming
See All in Programming
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
4
570
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
220
Realtime API 入門
riofujimon
0
140
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
180
色々なIaCツールを実際に触って比較してみる
iriikeita
0
310
WEBエンジニア向けAI活用入門
sutetotanuki
0
330
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
190
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
160
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.3k
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
100
現場で役立つモデリング 超入門
masuda220
PRO
15
3.1k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
510
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Code Review Best Practice
trishagee
64
17k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
RailsConf 2023
tenderlove
29
890
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
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Λ࣮ͬͯݱ͍ͯ͠Δ