Naruhounix
by
Koji SHIMADA
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
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灇瑔⠓劦䌽㣐⠓