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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
630
言語モデルによるAI創薬の進展 / Advancements in AI-Driven Drug Discovery Using Language Models
tsurubee
2
650
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
こんなアーキテクチャ図は嫌だ BEYOND THE TIME: 半年後の自分へ贈る15のメッセージ / 15 of Anti-pattern in AWS Architecture Diagrams
naospon
3
300
[2026-09-11]SREは誰のもの?運用エンジニアが始める 「SRE領域への越境」とチームの進化の軌跡 〜Road to NEXT CRE
tosite
0
120
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/6 - 2026/8
oracle4engineer
PRO
0
140
OpenTelemetry eBPF Instrumentationの舞台裏 / Behind the Scenes of OpenTelemetry eBPF Instrumentation
ymotongpoo
3
980
クロスボーダーM&AのValue Upを支えるプロダクト開発。日米チームのハブになったプロダクトエンジニアの実践 / Product Engineering Conference 2026
genda
0
110
あるけみー式LTスライド作成術
alchemy1115
1
170
ペアプロの価値はコードを書くことだけじゃない
codmoninc
PRO
0
160
Sigmaユーザーのための有用リソース一挙公開 & Sigmaで使えるMCP #sigma_ucj /useful-resources-for-sigma-computing-users-and-mcps-with-sigma
shinyaa31
0
180
Multica × 長期記憶:40個のミニプロジェクト管理
eiei114
1
240
#jawssonic2026 あの時代が悪かった ~動かなかったSageMakerと共に迎えたイベント当日~
ktkn1129
0
140
AI時代のAPI品質を支えるガードレール / API Guardrails for API quality in the AI era
yokawasa
1
210
AI活用の現在地、 ちゃんと見えてますか?/XPfest-2026
visional_engineering_and_design
0
180
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
Become a Pro
speakerdeck
PRO
31
6.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
30 Presentation Tips
portentint
PRO
1
390
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
490
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
310
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
460
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.2k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
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͔Β֬ೝͰ͖Δɻ ࠓճͨ͜͠ͱҎ֎ʹ͍Ζ͍Ζಛ͕͋ΔͷͰɺ ͦΕ·ͨ࣍ճʂ ʻྫʼ ɾݽࣇϓϩηε ɾκϯϏϓϩηε ɾσʔϞϯϓϩηε
ɾιέοτ௨৴ ɾϚϧνϓϩηεॲཧ
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ʂ