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
Daemonize
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Sergey Arkhipov
May 20, 2017
Programming
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Daemonize
A little tech talk for rannts#16 meetup on correct daemonization in UNIXes before systed era
Sergey Arkhipov
May 20, 2017
More Decks by Sergey Arkhipov
See All by Sergey Arkhipov
Fingerprinting
9seconds
0
200
Concurrency Models
9seconds
0
310
Probablistic Data Structures
9seconds
0
290
Own Mustache
9seconds
0
380
Stuff That Works
9seconds
0
400
Evidence
9seconds
0
130
Redneck Monads
9seconds
1
150
Latency
9seconds
0
170
Oh Blindfold Russia!
9seconds
0
340
Other Decks in Programming
See All in Programming
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.4k
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
130
Jetpack Compose Mechanisms
skydoves
3
800
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
420
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
150
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
400
contenteditable と日本語入力に向き合う
colorful12
0
200
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
150
SREの越境 / SRE Collaboration
y0hgi
2
310
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
24
27k
すこし踏み込む CancellationToken
htkym
2
1.7k
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
The SEO Collaboration Effect
kristinabergwall1
1
590
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
600
Side Projects
sachag
456
43k
Leo the Paperboy
mayatellez
10
2.4k
Thoughts on Productivity
jonyablonski
76
5.4k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
520
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
Transcript
Правильная демонизация Сергей Архипов, 2017
Чего хотим #!/usr/bin/env python3 # -*- coding: utf-8 -*- import
contextlib import syslog import time @contextlib.contextmanager def daemonize(): yield if __name__ == "__main__": with daemonize(): syslog.openlog(facility=syslog.LOG_USER) syslog.syslog("Daemon start.") time.sleep(10) syslog.syslog("Daemon done.")
Подход 1 def daemonize(): first_pid = os.fork() if first_pid: sys.exit(0)
yield
Подход 2 def daemonize(): first_pid = os.fork() if first_pid: sys.exit(0)
syslog.syslog("Session={0}, Group={1}, Parent={2}, Self={3}".format( os.getsid(0), os.getpgid(0), os.getppid(), os.getpid() )) yield … Session=7087, Group=14115, Parent=14115, Self=14151 … Daemon start. … Daemon done.
Подход 2 def daemonize(): first_pid = os.fork() if first_pid: sys.exit(0)
syslog.syslog("Session={0}, Group={1}, Parent={2}, Self={3}".format( os.getsid(0), os.getpgid(0), os.getppid(), os.getpid() )) os.setsid() syslog.syslog("Session={0}, Group={1}, Parent={2}, Self={3}".format( os.getsid(0), os.getpgid(0), os.getppid(), os.getpid() )) yield … Session=7087, Group=17364, Parent=17364, Self=17400 … Session=17400, Group=17400, Parent=17364, Self=17400 … Daemon start … Daemon done.
Подход 3 def daemonize(): if os.fork(): sys.exit(0) os.setsid() if os.fork():
sys.exit(0) yield
Подход 4 def daemonize(): if os.fork(): sys.exit(0) os.setsid() if os.fork():
sys.exit(0) os.chdir("/") os.umask(0o002) yield
Подход 5 def daemonize(): if os.fork(): sys.exit(0) os.setsid() if os.fork():
sys.exit(0) os.chdir("/") os.umask(0o002) sys.stdout.flush() sys.stderr.flush() _, max_fds = resource.getrlimit(resource.RLIMIT_NOFILE) max_fds = max_fds if max_fds!=resource.RLIM_INFINITY else 1024 os.closerange(0, max_fds) sys.stdout = sys.stderr = open(os.devnull, "w") sys.stdin = open(os.devnull, "r") yield
Подход 6 def daemonize(): if os.getppid() != 1: return if
os.fork(): sys.exit(0) os.setsid() if os.fork(): sys.exit(0) os.chdir("/") os.umask(0o002) sys.stdout.flush() sys.stderr.flush() _, max_fds = resource.getrlimit(resource.RLIMIT_NOFILE) max_fds = max_fds if max_fds != resource.RLIM_INFINITY else 1024 os.closerange(0, max_fds) sys.stdout = sys.stderr = open(os.devnull, "w") sys.stdin = open(os.devnull, "r") yield
def daemonize(): if os.getppid() != 1: return if os.fork(): sys.exit(0)
os.setsid() if os.fork(): sys.exit(0) os.chdir("/") os.umask(0o002) sys.stdout.flush() sys.stderr.flush() _, max_fds = resource.getrlimit(resource.RLIMIT_NOFILE) max_fds = max_fds if max_fds != resource.RLIM_INFINITY else 1024 os.closerange(0, max_fds) sys.stdout = sys.stderr = open(os.devnull, "w") sys.stdin = open(os.devnull, "r") yield