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
3.6k
フロントエンドチーム立ち上げで学んだTips / What I learned from organizing the new frontend team
indigolain
0
600
Persisted-queryをやってみた
indigolain
1
960
TEC DEPT 201610 Catal Engineer5期生募集
indigolain
0
440
なるほどUNIXプロセス10~11章
indigolain
0
91
なるほどUNIXプロセス4~5章
indigolain
0
120
Other Decks in Programming
See All in Programming
「コンパイル時のユニットテスト」導入するとユニットテストを 書かなくてよくなるのか?
tomohisa
9
2.1k
Understanding Ast By Looking
inouehi
0
120
Laravel標準バリデーションでできること
hmb_ok
2
360
孤独のCTOグルメという やや奇抜な企画をやった目的と効果
shoheimitani
3
1k
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
480
決断するための勇気、そのためのBacklog / Courage to make decisions, Backlog for that.
seike460
PRO
4
1.9k
CSRF対策のやり方、そろそろアップデートしませんか / Update your knowledge of CSRF protection
hiro_y
25
14k
プロンプトエンジニアリング入門
tomokusaba
2
970
Data Contracts In Practice With Debezium and Apache Flink (Kafka Summit London)
gunnarmorling
2
270
TCA魔法学入門🪄
dazy
0
280
自動テスト実行結果の目的を整理する / Organizing objectives of automated test results
twada
PRO
10
2.1k
Why 1 + 1 = 2 in Swift?
1plus4
1
240
Featured
See All Featured
Debugging Ruby Performance
tmm1
68
11k
[RailsConf 2023] Rails as a piece of cake
palkan
21
3.8k
Building an army of robots
kneath
300
41k
Imperfection Machines: The Place of Print at Facebook
scottboms
257
12k
Build The Right Thing And Hit Your Dates
maggiecrowley
23
1.9k
Done Done
chrislema
178
15k
Keith and Marios Guide to Fast Websites
keithpitt
407
22k
The Cult of Friendly URLs
andyhume
72
5.6k
Designing for humans not robots
tammielis
247
25k
Faster Mobile Websites
deanohume
296
30k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
225
51k
Git: the NoSQL Database
bkeepers
PRO
421
63k
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Λ࣮ͬͯݱ͍ͯ͠Δ