Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Pythonで学ぶUnixプロセスの基礎
Search
tsurubee
December 20, 2017
Technology
7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Pythonで学ぶUnixプロセスの基礎
「なるほどUnixプロセス」をPythonで学ぶ
tsurubee
December 20, 2017
More Decks by tsurubee
See All by tsurubee
大規模言語モデルにおけるData-Centric AIと合成データの活用 / Data-Centric AI and Synthetic Data in Large Language Models
tsurubee
1
670
言語モデルによるAI創薬の進展 / Advancements in AI-Driven Drug Discovery Using Language Models
tsurubee
2
670
AIトップカンファレンスからみるData-Centric AIの研究動向 / Research Trends in Data-Centric AI: Insights from Top AI Conferences
tsurubee
3
3.5k
DeepCrysTet: A Deep Learning Approach Using Tetrahedral Mesh for Predicting Properties of Crystalline Materials
tsurubee
0
1.4k
3次元メッシュで表現した結晶構造を用いた材料物性の予測に向けた深層学習モデルの設計 / Design of Deep Learning Model for Predicting Material Properties Using Crystal Structure Represented by Three-Dimensional Mesh
tsurubee
1
2.6k
分散システムの性能異常に対する機械学習の解釈性に基づく原因診断手法 / A Method for Diagnosing the Causes of Performance Issues in Distributed Systems Based on the Interpretability of Machine Learning
tsurubee
0
1.8k
機械学習の解釈性に関する研究動向とシステム運用への応用 / A Survey on Interpretable Machine Learning and Its Application for System Operation
tsurubee
0
400
機械学習モデルの局所的な解釈に着目したシステムにおける異常の原因診断手法の構想
tsurubee
0
8.2k
アニーリングマシンを活用したエッジAIにおける 生成モデルの学習効率化のためのアーキテクチャ
tsurubee
0
1.7k
Other Decks in Technology
See All in Technology
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
170
使いこなすために知っておきたい Azure SRE Agent アンチパターン
torumakabe
2
500
Refining Active Record
shugo
0
110
夫婦で子育てするための育児標準化
codmoninc
PRO
0
210
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
180
AIは「聞けば答える」から「任せると自分で進める」へ - JACTIMペナン地域部会・ペナン三水会講演
knishioka
0
110
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
1
400
Loop Engineering これくらいでいい
mikanichinose
0
240
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
110
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
110
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
6
4.5k
Getting Started with Google Antigravity
glaforge
0
270
Featured
See All Featured
Being A Developer After 40
akosma
92
590k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Claude Code のすすめ
schroneko
67
230k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
The Language of Interfaces
destraynor
162
27k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
450
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Between Models and Reality
mayunak
4
490
What's in a price? How to price your products and services
michaelherold
247
13k
Transcript
1ZUIPOͰֶͿ 6OJYϓϩηεͷجૅ 1Z'VLVPLB
ࣗݾհ ͭΔͨ ʢ!UTVSVCFFʣ ΤϯδχΞྺɿ ͪΐ͍ େֶͷઐ߈Խֶ લ৬ফ࢜ झຯےτϨ ʢಛʹϕϯνϓϨεʣ
ࠓճͷత Θ͔ͬͨΑ͏ͰΘ͔Βͳ͍ʮϓϩηεʯʹ͍ͭͯ 1ZUIPOΛ༻͍ͯཧղΛਂΊΔ͜ͱɻ ͜ͷຊΛࢀߟʹ ͠·ͨ͠ɻ Φεεϝʂ ಈ࡞ڥɿ6CVOUV ʢ7JSUVBM#PY্ʹߏஙʣ ࢀߟจݙ
࣍ l ϓϩηεͱʁ l ϓϩηεͱʁ l ϓϩηεʹ*%͕͋Δ l ϓϩηεʹ͕͍Δ l
ϓϩηεͷϦιʔεΛݟͯΈΑ͏ʂ l ϓϩηεΛ࡞Δ l ϓϩηεࢠϓϩηεΛ࡞ΕΔ l GPSLͷڍಈΛͬͯΈΑ͏ʂ l ϓϩηεؒ௨৴ l ϓϩηεؒ௨৴ͱʁ l ύΠϓʹΑΔ௨৴ l ·ͱΊ
ϓϩηεͱʁ
ϓϩάϥϜͷ࣮ߦத ͷ࢟Ͱ͋Δɻ ϓϩηεͱʁ
ϓϩηεʹ*%͕͋Δ $ ps u USER PID %CPU %MEM VSZ RSS
TTY STAT START TIME COMMAND ubuntu 2005 0.0 0.5 21392 5392 pts/0 Ss+ 02:21 0:00 –bash ubuntu 2212 0.1 0.5 21388 5260 pts/1 Ss 06:18 0:00 –bash ubuntu 2228 0.0 0.3 36084 3348 pts/1 R+ 06:18 0:00 ps u 1ZUIPOͰɾɾ $ python >>> import os >>> os.getpid() 1229 QTίϚϯυ 04ͷػೳΛར༻͢ΔͨΊͷʮPTʯͱ͍͏ඪ४ϥΠϒϥϦ͕͋Δɻ 1*%୯ʹ࿈൪ʹͳ͍ͬͯΔͷϥϕϧͰ͋Δɻ
ϓϩηεʹ͕͍Δ QTUSFFίϚϯυ $ pstree systemd─┬─VBoxService─┬─{automount} │ ├─{control} │ ├─{cpuhotplug} │
├─{memballoon} │ ├─{timesync} │ ├─{vminfo} │ └─{vmstats} ├─polkitd─┬─{gdbus} │ └─{gmain} ├─snapd───6*[{snapd}] ├─sshd─┬─sshd───sshd───bash │ └─sshd───sshd───bash───pstree ├─systemd───(sd-pam) ├─systemd-journal ˞Ұ෦লུ ϓϩηεͷࢠؔΛπϦʔදࣔͰ͖Δɻ QTUSFFCBTIͷࢠ
ϓϩηεʹ͕͍Δ ϓϩηεͷ*%Λऔಘ͢Δ ͍͍ͨͯͷ߹ɺϓϩηεͦͷϓϩηεΛىಈͨ͠ ϓϩηεͱͳΔɻ $ python >>> import os >>>
os.getppid() 1165 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.9 0.5 37916 5976 ? Ss 06:43 0:08 /sbin/init ͯ͢ͷى1*%͕ͷJOJUϓϩηε ʢγεςϜىಈ࣌ʹ࠷ॳʹ্ཱ͕ͪΔϓϩηεʣ ΛͨͲ͍ͬͯ͘ͱɾɾ
ϓϩηεͷϦιʔεΛݟͯΈΑ͏ʂ l TUBUVT l DXE l FOWJSPO l FYF l
UBTL l NBQT ͳͲ QSPDϓϩηε*%
ϓϩηεΛ࡞Δ
ϓϩηεࢠϓϩηεΛ࡞ΕΔ l GPSL γεςϜίʔϧʹΑͬͯɺ࣮ߦதͷϓϩηε͔Β ৽͍͠ϓϩηεΛੜͰ͖Δɻ l GPSL ΛݺͿଆͷϓϩηεʮϓϩηεʯɺੜ͞Ε
ΔϓϩηεʮࢠϓϩηεʯͱͳΔɻ l ࢠϓϩηεɺϓϩηεͰΘΕ͍ͯΔͯ͢ͷϝϞ Ϧͷίϐʔͱɺϓϩηε͕։͍͍ͯΔϑΝΠϧσΟε ΫϦϓλΛҾ͖ܧ͙ɻ
GPSLͷڍಈΛͬͯΈΑ͏ import os if os.fork(): print("Here in the if block.")
else: print("Here in the else block.") $ python fork.py Here in the if block. Here in the else block. ࣮ߦ JG۟FMTF࣮۟ߦ͞Ε͍ͯΔɻͳʹ͕ى͖ͯΔʁ GPSL͢ΔͱԿ͕ى͖Δͷ͔ʁ fork.py
GPSLͷڍಈΛͬͯΈΑ͏ import os print("---- before fork ----") print("pid: {0}".format(os.getpid())) if
os.fork(): print("----- if block ------") print("pid: {0}".format(os.getpid())) else: print("---- else block -----") print("pid: {0}".format(os.getpid())) $ python fork.py ---- before fork ---- pid: 1547 ----- if block ------ pid: 1547 ---- else block ----- pid: 1548 ࣮ߦ JG͕۟ϓϩηεɺ FMTF͕۟ࢠϓϩηε ʹΑ࣮ͬͯߦ͞Ε͍ͯΔɻ ϓϩηε*%͕Ͳ͏ͳ͍ͬͯΔ͔ௐΔ fork.py
GPSLͷڍಈΛͬͯΈΑ͏ import os ret = os.fork() if ret: print("----- if
block ------") print("return value: {0}".format(ret)) else: print("---- else block -----") print("return value: {0}".format(ret)) $ python fork.py ----- if block ------ return value: 1548 ---- else block ----- return value: 0 ࣮ߦ ϓϩηεଆʹʮੜͨ͠ࢠϓϩηεͷ1*%ʯΛฦ͠ɺ ࢠϓϩηεଆʹʮʯΛฦ͢ɻ GPSLͷฦΓ͕Ͳ͏ͳ͍ͬͯΔ͔ௐΔ fork.py
ϓϩηεؒ௨৴
ϓϩηεؒ௨৴ͱʁ ϓϩηεؒ௨৴ʢ*1$*OUFS1SPDFTT$PNNVOJDBUJPOʣͱɺ ෳͷϓϩηεؒͰσʔλΛΓͱΓ͢ΔͨΊͷΈͰ͋Δɻ *1$ͷख๏༷ʑ ɾڞ༗ϝϞϦ ɾγάφϧ ɾύΠϓ ɾιέοτ ɾηϚϑΥ ɾϝοηʔδύογϯά
ͳͲ
ϓϩηεؒ௨৴ͱʁ ϓϩηεؒ௨৴ʢ*1$*OUFS1SPDFTT$PNNVOJDBUJPOʣͱɺ ෳͷϓϩηεؒͰσʔλΛΓͱΓ͢ΔͨΊͷΈͰ͋Δɻ *1$ͷख๏༷ʑ ɾڞ༗ϝϞϦ ɾγάφϧ ɾύΠϓ ɾιέοτ ɾηϚϑΥ ɾϝοηʔδύογϯά
ͳͲ ࠓίϨʂ
ύΠϓʹΑΔ௨৴ ύΠϓࢠؔʹ͋Δϓϩηεؒͷ୯ํͷ௨৴ Ϣʔβۭؒ Χʔωϧۭؒ ϑΝΠϧσΟεΫϦϓλ ϑΝΠϧσΟεΫϦϓλ
ϓϩηε ࢠϓϩηε σΟεϓϨΠ ΩʔϘʔυ ύΠϓ ࢀߟɿIUUQXXXDPJOTUTVLVCBBDKQdZBTDPJOTTZTQSP GPSL
ύΠϓʹΑΔ௨৴ import os reader, writer = os.pipe() if os.fork(): os.close(reader)
write_pipe = os.fdopen(writer, 'w') write_pipe.write('Hello child!') write_pipe.close() else: os.close(writer) read_pipe = os.fdopen(reader, 'r') message= read_pipe.readline() read_pipe.close() print(message) pipe.py $ python pipe.py Hello child! ࣮ߦ ϓϩηε ࢠϓϩηε
·ͱΊ ϓϩηεɺ*%͕͋ͬͯɺ͕͍ͯɺࢠΛ࡞Εͯɺ ௨৴͕Ͱ͖Δɻ ͦͯ͠ɺͦͷ༷ࢠΛ1ZUIPO͔Β֬ೝͰ͖Δɻ ࠓճͨ͜͠ͱҎ֎ʹ͍Ζ͍Ζಛ͕͋ΔͷͰɺ ͦΕ·ͨ࣍ճʂ ʻྫʼ ɾݽࣇϓϩηε ɾκϯϏϓϩηε ɾσʔϞϯϓϩηε
ɾιέοτ௨৴ ɾϚϧνϓϩηεॲཧ
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ʂ