Slide 1

Slide 1 text

ͳΔ΄Ͳ 6/*9 ϓϩηε Koji Shimada @snoozer05 3VCZד6OJYך㛇燉׾㷕רֲ 04$)0,,"*%0KVT灇瑔⠓劦䌽㣐⠓

Slide 2

Slide 2 text

http://ruby-sapporo.org 3VCZ4BQQPSP

Slide 3

Slide 3 text

http://www.jus.or.jp 傈劤6/*9ِ٦ؠ⠓

Slide 4

Slide 4 text

ͳΔ΄Ͳ 6/*9 ϓϩηε Koji Shimada @snoozer05 3VCZד6OJYך㛇燉׾㷕רֲ 04$)0,,"*%0KVT灇瑔⠓劦䌽㣐⠓

Slide 5

Slide 5 text

http://tatsu-zine.com/books/naruhounix

Slide 6

Slide 6 text

ؔلٖ٦ذ؍ؚٝءأذي׾㹋鄲ׅ׷״ֲז فؚٗٓوぢֽדכזֻגծ6OJY׾ֲתְֿ ה⢪׏גفؚٗٓىؚٝדֹ׷״ֲחז׶׋ ְ➂ぢֽךⱁדׅկ ջז׷קו6OJYفٗإأռⰻ㺁稱➜ l

Slide 7

Slide 7 text

ؔلٖ٦ذ؍ؚٝءأذي׾㹋鄲ׅ׷״ֲז فؚٗٓوぢֽדכזֻגծ6OJY׾ֲתְֿ ה⢪׏גفؚٗٓىؚٝדֹ׷״ֲחז׶׋ ְ➂ぢֽךⱁדׅկ ջז׷קו6OJYفٗإأռⰻ㺁稱➜ l

Slide 8

Slide 8 text

http://razokulover.hateblo.jp/entry/2014/11/12/084645

Slide 9

Slide 9 text

http://yuuki.hatenablog.com/entry/2015-webserver-architecture

Slide 10

Slide 10 text

3VCZד㷕ע

Slide 11

Slide 11 text

http://tatsu-zine.com/books/naruhounix

Slide 12

Slide 12 text

http://tatsu-zine.com/books/naruhounix 3VCZכ6OJYך㶨⣘דׅկ 殛 3VCZך֮׵ײ׷הֿ׹כ6OJYךءأذي ؝٦ٕװ俑⻉٥䙼䟝׾⿾僥׃גְתׅկ

Slide 13

Slide 13 text

ͳΔ΄Ͳ 6/*9 ϓϩηε Koji Shimada RubySapporo 3VCZד6OJYך㛇燉׾㷕רֲ 04$)0,,"*%0KVT灇瑔⠓劦䌽㣐⠓

Slide 14

Slide 14 text

فٗإأ׏ג ♧⡤ו׿ז׮ך

Slide 15

Slide 15 text

فٗإأהכ ˖ 㹋遤⚥ךفؚٗٓيך㹋⡤ ˖ ׅץגך؝٦سכفٗإأ♳ד㹋遤ׁ׸׷ % ps -x PID TTY TIME CMD 326 ?? 0:20.78 /usr/libexec/UserEventAgent (Aqua) 328 ?? 6:57.66 /usr/sbin/distnoted agent 329 ?? 0:08.13 /usr/sbin/universalaccessd launchd -s 330 ?? 0:44.20 /usr/sbin/cfprefsd agent 333 ?? 1:50.07 /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock 335 ?? 11:16.33 /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/… 336 ?? 4:03.26 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder ... ֿך遤遤ָ植㖈㹋遤⚥ךفٗإأ 痥畍չ劤剅ך䩛䒷ֹպ

Slide 16

Slide 16 text

3VCZ׾⢪׏ג⡤꿀 % irb > 㹋遤⚥ךJSCךفٗإأ׾然钠דֹ׷ אךة٦ىشٕדJSC׾饯⹛׃גֶֹ ׮ֲאךة٦ىشٕדQT؝وٝس׾㹋遤ׅ׷ % ps PID TTY TIME CMD 35558 ttys000 0:00.13 -zsh 38910 ttys000 0:00.53 irb 38956 ttys001 0:00.15 -zsh

Slide 17

Slide 17 text

فٗإأחכ*%ָ֮׷ ˖ ぐفٗإأכ♧䠐ז*% فٗإأ*% ׾䭯א ˖ 3VCZדכ1SPDFTTQJEד然钠דֹ׷ % irb > Process.pid => 38910 % ps PID TTY TIME CMD 35558 ttys000 0:00.13 -zsh 38910 ttys000 0:00.53 irb 38956 ttys001 0:00.15 -zsh QT؝وٝسדכ1*%⴨ד׉׸׊׸ךفٗإأ*%׾然钠דֹ׷ 痥畍չفٗإأחכ*%ָ֮׷պ

Slide 18

Slide 18 text

垥彊أزٔ٦ي ˖ فٗإأחכ垥彊أزٔ٦يָֻ׏אְגֻ׷ ˖ 垥彊Ⰵ⸂ծ垥彊⳿⸂ծ垥彊ؒٓ٦⳿⸂ךא ˖ ׉׸׊׸ךⰅ⳿⸂כ鸐䌢ة٦ىشٕה籬ָ׏גְ׷ فٗإأ λʔϛφϧ 垥彊Ⰵ⸂ 垥彊⳿⸂ ؗ٦ن٦س ر؍أفٖ؎ 痥畍չفٗإأחכؿ؋؎ٕر؍أؙٔفةָ֮׷պ

Slide 19

Slide 19 text

> input = STDIN.gets foo => “foo¥n” > STDOUT.puts “bar” bar => nil 3VCZ׾⢪׏ג⡤꿀 ס׌׿⢪׏גְ׷QVUTװHFUT׾ծ״׶⿑㺘ח邌植ׅ׷ה˘ 3VCZדכ45%*/ծ45%065ծ45%&33ד⿫撑דֹ׷ > STDIN => #> > STOUT => #>

Slide 20

Slide 20 text

ؿ؋؎ٕر؍أؙٔفة ˖ 垥彊Ⰵ⳿⸂׮ؿ؋؎ٕⰅ⳿⸂׮ծ04ַ׵כׅץ גずׄ״ֲז׮ךٔا٦أה׃ג䪔׻׸׷ ˖ فٗإأָ籬ָ׏גְ׷ٔا٦أכչؿ؋؎ٕ ر؍أؙٔفةպהְֲ♧䠐ז侭侧⦼ה׃ג邌 植ׁ׸׷ 痥畍չفٗإأחכؿ؋؎ٕر؍أؙٔفةָ֮׷պ ؿ؋؎ٕ ؗ٦ن٦س λʔϛφϧ فٗإأ ر؍أفٖ؎ GE GE GE

Slide 21

Slide 21 text

3VCZדכMFOPדؿ؋؎ٕر؍أؙٔفة׾然钠דֹ׷ >> STDIN.fileno => 0 >> STDOUT.fileno => 1 >> STDERR.fileno => 2 >> file = File.open(“a.txt”, “w”) => # >> file.fileno => 9 㢩鿇ؿ؋؎ٕפךⰅ⳿⸂׮ずׄ״ֲח盖椚ׁ׸גְ׷ֿהָ׻ַ׷ 3VCZ׾⢪׏ג⡤꿀

Slide 22

Slide 22 text

ٔت؎ؙٖءّٝ 垥彊Ⰵ⳿⸂⯓׾ؿ؋؎ٕח➰ֽ剏ִ׷ $ wc -l < in.txt Ⰵ⸂ٔت؎ؙٖءّٝ ⳿⸂ٔت؎ؙٖءّٝ $ ps > out.txt ず儗ח遤ֲ $ wc -l < in.txt > out.txt

Slide 23

Slide 23 text

file = File.open(“out.txt”, “w”) STDOUT.reopen(file) puts “ඪ४ग़ྗઌ͕มΘ͍ͬͯΔ͸ͣ” 3VCZ׾⢪׏ג⡤꿀 SFPQFO׾⢪ֲֿהדⰅ⳿⸂⯓׾➰ֽ剏ִ׵׸׷ SFEJSFDUJPO@FYBNQMFSC $ ruby redirection_example.rb $ cat out.txt ඪ४ग़ྗઌ͕มΘ͍ͬͯΔ͸ͣ ⹛⡲然钠

Slide 24

Slide 24 text

ֿֿתדךתה׭

Slide 25

Slide 25 text

فؚٗٓيכفٗإأה׃ג㹋遤ׁ׸׷ $ ls ة٦ىشַٕ׵؝وٝس׾㹋遤ׅ׷ה˘

Slide 26

Slide 26 text

فؚٗٓيכفٗإأה׃ג㹋遤ׁ׸׷ MT׾㹋遤ׅ׷ فٗإأ $ ls ة٦ىشַٕ׵؝وٝس׾㹋遤ׅ׷ה˘

Slide 27

Slide 27 text

فٗإأחכ*%ָ֮׷ MT׾㹋遤ׅ׷ فٗإأ $ ls ϓϩηε*%͸

Slide 28

Slide 28 text

فٗإأכ垥彊أزٔ٦ي׾䭯א فٗإأ $ ls ة٦ىشٕ ر؍أفٖ؎ ؗ٦ن٦س 垥彊Ⰵ⸂ 垥彊⳿⸂

Slide 29

Slide 29 text

垥彊أزٔ٦ي׮ؿ؋؎ٕ׮ׅץגָٔا٦أה׃ג盖椚ׁ׸׷ $ ls ة٦ىشٕ 垥彊Ⰵ⸂ 垥彊⳿⸂ ؿ؋؎ٕ ؿ؋؎ٕ⳿⸂ ؗ٦ن٦س ر؍أفٖ؎

Slide 30

Slide 30 text

ٔا٦أכؿ؋؎ٕر؍أؙٔفةה׃ג盖椚ׁ׸׷ $ ls ة٦ىشٕ 殢湡ךٔا٦أ 殢湡ךٔا٦أ ؿ؋؎ٕ 殢湡ךٔا٦أ ؗ٦ن٦س ر؍أفٖ؎

Slide 31

Slide 31 text

فٗإأחכ鋵ְָ׷ ˖ ׅץגךفٗإأחכ鋵הז׷فٗإأָ㶷㖈ׅ׷ ˖ 3VCZדכ1SPDFTTQQJEד然钠דֹ׷ % irb > Process.ppid => 38910 % ps -l UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD 501 35558 35557 4006 0 31 0 2481048 3920 - S 0 ttys000 0:00.13 -zsh 501 38910 35558 4046 0 31 0 2497224 12768 - S+ 0 ttys000 0:00.55 irb 501 38956 38955 4006 0 31 0 2491288 4184 - S 0 ttys001 0:00.15 -zsh QT؝وٝسדכ11*%⴨ד鋵فٗإأך*%׾然钠דֹ׷ JSCفٗإأך鋵فٗإأכ[TIفٗإأד֮׷ֿהָ׻ַ׷ 痥畍չفٗإأחכ鋵ְָ׷պ

Slide 32

Slide 32 text

荈ⴓָ鋵חז׷ GPSLׅ׷ֿהדծ荈ⴓָ鋵חז׷ֿהָדֹ׷ puts “ࣗ෼: PID(#{Process.pid}) PPID(#{Process.pid})” pid = fork do puts “ ࢠ: PID(#{Process.pid}) PPID(#{Process.pid})” end Process.waitpid(pid) GPSL@FYBNQMFSC $ ruby fork_example.rb ࣗ෼: PID(45261) PPID(35558) ɹࢠ: PID(45306) PPID(45261) ⹛⡲然钠 痥畍չفٗإأכ㶨فٗإأ׾⡲׸׷պ

Slide 33

Slide 33 text

荈ⴓָ鋵חז׷ GPSLׅ׷ֿהדծ荈ⴓָ鋵חז׷ֿהָדֹ׷ puts “ࣗ෼: PID(#{Process.pid}) PPID(#{Process.pid})” pid = fork do puts “ ࢠ: PID(#{Process.pid}) PPID(#{Process.pid})” end Process.waitpid(pid) GPSL@FYBNQMFSC SVCZفؚٗٓي׾ 㹋遤⚥ךفٗإأ SVCZفؚٗٓي׾ 㹋遤⚥ךفٗإأ ך醱醡 SVCZفؚٗٓي׾ 㹋遤⚥ךفٗإأ ך醱醡 GPSLָㄎן⳿ׁ׸׷ה 荈ⴓ׾؝ؾ٦׃ג 倜׃ְفٗإأָ⡲׵׸׷

Slide 34

Slide 34 text

荈ⴓָ鋵חז׷ GPSLׅ׷ֿהדծ荈ⴓָ鋵חז׷ֿהָדֹ׷ puts “ࣗ෼: PID(#{Process.pid}) PPID(#{Process.pid})” pid = fork do puts “ ࢠ: PID(#{Process.pid}) PPID(#{Process.pid})” end Process.waitpid(pid) GPSL@FYBNQMFSC SVCZفؚٗٓي׾ 㹋遤⚥ךفٗإأ SVCZفؚٗٓي׾ 㹋遤⚥ךفٗإأ ך醱醡 欰䧭ׁ׸׋فٗإأכ ـٗحؙך⚥׌ֽ׾㹋遤ׅ׷ ⯋ךفٗإأכ׉ך䖓׾ 㹋遤׃גְֻ

Slide 35

Slide 35 text

㶨⣘חⴽך麣׾遤ַׇ׷ FYFD׾⢪ֲהⴽךفؚٗٓي׾㹋遤ׅ׷فٗإأח 㢌魦ׇׁ׷ֿהָדֹ׷ pid = fork do exec “ps”, “-l” puts “͜͜ͷॲཧ͸΋͏ಈ͔ͳ͍” end Process.waitpid(pid) puts “psίϚϯυ͕࣮ߦ͞Εͨ͸ͣ” GPSL@FYFD@FYBNQMFSC $ ruby fork_exec_example.rb fork_exec_example.rb:2: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777 UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD 501 22184 22183 4006 0 31 0 2499544 6856 - S 0 ttys000 0:00.35 -zsh 501 25237 22184 4046 0 31 0 2447816 7080 - S+ 0 ttys000 0:00.05 ruby -w0 fork_exec_example.rb pwdίϚϯυ͕࣮ߦ͞Εͨ͸ͣ ⹛⡲然钠 痥畍չ畭劣فٗإأ׾⡲׷պ

Slide 36

Slide 36 text

ֿֿתדךתה׭

Slide 37

Slide 37 text

فٗإأכفٗإأַ׵欰䧭ׁ׸׷ $ ls ة٦ىشַٕ׵؝وٝس׾㹋遤ׅ׷הכ˘

Slide 38

Slide 38 text

ءٕؑ׾㹋遤׃גְ׷ فٗإأ $ ls فٗإأכفٗإأַ׵欰䧭ׁ׸׷ Ⰵ⸂ׁ׸׋ⰻ㺁׾ءٕؑفٗإأָ鍑ꅸ׃ג 垥彊⳿⸂ 垥彊Ⰵ⸂ MT 垥彊⳿⸂

Slide 39

Slide 39 text

ءٕؑ׾㹋遤׃גְ׷ فٗإأ $ ls فٗإأכفٗإأַ׵欰䧭ׁ׸׷ GPSL׃גفٗإأ׾醱醡׃ 垥彊Ⰵ⸂ 垥彊⳿⸂ ءٕؑ׾㹋遤׃גְ׷ فٗإأ 垥彊Ⰵ⸂ 垥彊⳿⸂

Slide 40

Slide 40 text

ءٕؑ׾㹋遤׃גְ׷ فٗإأ $ ls فٗإأכفٗإأַ׵欰䧭ׁ׸׷ FYFD׃ג؝وٝس׾㹋遤ׅ׷فٗإأח㢌魦ׇׁ׷ 垥彊Ⰵ⸂ 垥彊⳿⸂ MT׾㹋遤׃גְ׷ فٗإأ 垥彊Ⰵ⸂ 垥彊⳿⸂

Slide 41

Slide 41 text

ءٕؑ׾㹋遤׃גְ׷ فٗإأ $ ls فٗإأכفٗإأַ׵欰䧭ׁ׸׷ FYFD׃ג؝وٝس׾㹋遤ׅ׷فٗإأח㢌魦ׇׁ׷ 垥彊Ⰵ⸂ 垥彊⳿⸂ MT׾㹋遤׃גְ׷ فٗإأ 垥彊Ⰵ⸂ 垥彊⳿⸂ 穠卓׾⳿⸂

Slide 42

Slide 42 text

ءٕؑ׾㹋遤׃גְ׷ فٗإأ $ ls فٗإأכفٗإأַ׵欰䧭ׁ׸׷ Ⳣ椚׾穄ִ׷ה㶨فٗإأכ穄✪ׅ׷ 垥彊Ⰵ⸂ 垥彊⳿⸂

Slide 43

Slide 43 text

׈׿ע׾籬ֺさ׻ׇ׷

Slide 44

Slide 44 text

ػ؎ف

Slide 45

Slide 45 text

ػ؎ف ؝وٝسך穠卓׾ⴽך؝وٝسךⰅ⸂חׅ׷ $ ps -x | wc -l QT؝وٝسך穠卓ך遤侧׾XD؝وٝسדؕؐٝزׅ׷ ֿ׸ָ6/*9ךㆸ㷕ד֮׷կ♧אךֿה׾遤 ְծת׋׉׸׾ֲתֻװ׷فؚٗٓي׾剅 ֽկ⼿锃׃ג⹛ֻفؚٗٓي׾剅ֽկ .%وؗٗ؎ l

Slide 46

Slide 46 text

ػ؎ف ؝وٝسך穠卓׾ⴽך؝وٝسךⰅ⸂חׅ׷ וֲװ׏ג ˖ אך؝وٝسך垥彊⳿⸂ה垥彊Ⰵ⸂׾אז־׷ ˖ QJQFءأذي؝٦ٕ׾⢪׏ג׉׸׾㹋植ׅ׷ ˖ 3VCZדכ*0QJQF׾⢪׏גずֿׄהָדֹ׷ 痥畍չفٗإأכ鸐⥋דֹ׷պ

Slide 47

Slide 47 text

*0QJQF׾אַ׏ג׫׷ > write_io.puts “foo” => nil > write_io.puts “bar” => nil > read_io.gets => “foo¥n” > read_io.gets => “bar¥n” > read_io, write_io = IO.pipe => [#>IO:fd 9>, # ػ؎ف׾⡲䧭ׅ׷ ػ؎فח剅ֹ鴥׬ ػ؎ف׾铣׫⳿ׅ

Slide 48

Slide 48 text

*0QJQF׾אַ׏ג׫׷ >IO.pipe do |read_io, write_io| > write_io.puts “foo” > write_io.puts “bar” > p read_io.gets > p read_io.gets >end “foo¥n” “bar¥n” ـٗحؙ晛

Slide 49

Slide 49 text

QJQF׾⢪׏גְ׷הֹך؎ً٦آ فٗإأ XSJUF@JP SFBE@JP ػ؎ف ˑGPPdO˒ ˑCBSdO˒

Slide 50

Slide 50 text

ֿ׿ז괏ח⢪ֲֿהדػ؎ف׾㹋植דֹ׷ فٗإأ" λʔϛφϧ 垥彊Ⰵ⸂ 垥彊⳿⸂ فٗإأ# 垥彊Ⰵ⸂ 垥彊⳿⸂ ػ؎ف

Slide 51

Slide 51 text

3VCZ׾⢪׏ג⡤꿀ׅ׷

Slide 52

Slide 52 text

3VCZ׾⢪׏ג⡤꿀 IO.pipe do |read_io, write_io| fork do STDOUT.reopen(write_io) exec ‘ps’, ‘-x’ end fork do STDIN.reopen(read_io) exec ‘wc’, ‘-l’ end end Process.waitall QJQF@FYBNQMFSC ⹛⡲然钠 $ ruby pipe_example.rb

Slide 53

Slide 53 text

תה׭

Slide 54

Slide 54 text

➙傈װ׏׋ֿה ˖ فؚٗٓيכفٗإأה׃ג㹋遤ׁ׸׷ ˖ فٗإأכ*%׾䭯א ˖ فٗإأכ垥彊أزٔ٦يח籬ָ׏גְ׷ ˖ ٔا٦أכؿ؋؎ٕر؍أؙٔفة׾䭯א ˖ 鋵فٗإأה㶨فٗإأחאְג ˖ GPSLFYFDדⴽךفؚٗٓي׾㹋遤ׅ׷ ˖ فٗإأず㡦ךⰅ⳿⸂׾ػ؎فד籬־ג׫׷

Slide 55

Slide 55 text

➙傈װ׵זַ׏׋ֿה ˖ 橆㞮㢌侧ךֿה ˖ ؝وٝسٓ؎ٝ䒷侧ךֿה ˖ فٗإأ꟦ך鸐⥋חאְגך鑫稢 ˖ ءؚشٕךֿה ˖ ر٦ٌٝفٗإأךֿה ˖ 植㹋⚅歲דך⢽

Slide 56

Slide 56 text

http://tatsu-zine.com/books/naruhounix

Slide 57

Slide 57 text

http://www.garbagecollect.jp/~usa/d/201304c.html ջז׷קו6OJYفٗإأռד㷕ע 8JOEPXT晛3VCZך㛇燉

Slide 58

Slide 58 text

Comming Soon…

Slide 59

Slide 59 text

ͳΔ΄Ͳ 6/*9 ϓϩηε Koji Shimada RubySapporo 3VCZד6OJYך㛇燉׾㷕רֲ 04$)0,,"*%0KVT灇瑔⠓劦䌽㣐⠓