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
誤解されがちなsleepコマンドの挙動
Search
Satoru Takeuchi
PRO
July 11, 2020
Technology
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
誤解されがちなsleepコマンドの挙動
以下動画のテキストです。
https://youtu.be/kF1VicngujU
Satoru Takeuchi
PRO
July 11, 2020
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
79
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
110
あなたの知らないバージョン命名規則
sat
PRO
3
920
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
74
Machine Check Exception
sat
PRO
2
71
バイナリダンプの模様を読む
sat
PRO
0
110
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
110
114-ファイルのshallow_copy.pdf
sat
PRO
2
63
113-Btrfsのスナップショット.pdf
sat
PRO
0
47
Other Decks in Technology
See All in Technology
How to Design Configuration for Rails Applications
willnet
1
830
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
1
1.8k
会社紹介資料 / Sansan Company Profile
sansan33
PRO
31
430k
AI コーディングと人間の認知スループット / CTO Night & Day 2026 Morning Session / AI Coding and Human Cognitive Throughput
prog893
5
1.3k
Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
1
760
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
180
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
190
Browser Spec: Testing Hotwire with Ruby
takahashim
1
130
DBについての基礎説明(MySQL編) - コロプラ 2026年度 新卒研修
colopl
0
130
Optunaの最新リリースv5.0について
pfn
PRO
0
120
AIカンパニーへの転換を支えた、エンジニアの仕事の再定義
kworkdev
PRO
2
1.3k
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
930
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
Building the Perfect Custom Keyboard
takai
2
910
GraphQLとの向き合い方2022年版
quramy
50
15k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Designing for Timeless Needs
cassininazir
1
530
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
780
Transcript
誤解されがちな Sleepコマンドの挙動 Jul 11th, 2020 Satoru Takeuchi Twitter: satoru_takeuchi 1
もくじ • sleepコマンドに持たれがちなイメージ • Linuxのプロセススケジューリング • Sleepコマンドの実際 • まとめ 2
もくじ • sleepコマンドに持たれがちなイメージ • Linuxのプロセススケジューリング • Sleepコマンドの実際 • まとめ 3
sleepコマンドに持たれがちなイメージ • ちょうど引数で指定された秒数後に終了する • コマンドの仕様 ◦ Ubuntu 18.04の”Man sleep”より抜粋 Pause
for NUMBER seconds. 4
もくじ • sleepコマンドに持たれがちなイメージ • Linuxのプロセススケジューリング • Sleepコマンドの実際 • まとめ 5
Linuxのプロセススケジューリング • CPU上で複数実行可能プロセスnがいれば所定の時間づつ実行させる CPU上で動作 するプロセス n=1 n=2 n=3 同上 同上
P0 P0 P1 P0 P0 P1 P2 P0 P1 6 時間 * 本当はもうちょっと複雑です
“Sleep 1”コマンドがいる場合 7 CPU上で動作 するプロセス n=1 P0 P0 idle n>=2
P0 1秒 同上 P0以外 P0 または P0 P0以外 P0 P0以外 時間 nが大きいほど延びる 同上 実行開始 実行開始 実行開始 終了 終了 終了 nanosleep()システムコール(後述)呼び出し
もくじ • sleepコマンドに持たれがちなイメージ • Linuxのプロセススケジューリング • Sleepコマンドの実際 • まとめ 8
sleepコマンドの実際 • 少なくとも引数で指定された秒数待つ • sleepコマンドは内部的にnanosleep()システムコールを呼び出している ◦ 仕様をUbuntu 18.04の”Man nanosleep”より確認 •
× コマンド実行0.5秒後に終了 • 〇 コマンド実行2秒後に終了 nanosleep() suspends the execution of the calling thread until either at least the time specified in *req has elapsed, ... 9
実験 • 確認したいこと ◦ Sleepが指定された秒数よりもはるかに遅く終了しうること • やること 1. あるCPU上で大量に無限ループプログラムを実行 ▪
for ((i=0;i<1000;i++)) ; do taskset -c 0 ./sleep 1 & done 2. 同じCPU上でsleepプログラムを実行して経過時間を確認 ▪ Time taskset -c 0 sleep 1 10
もくじ • sleepコマンドに持たれがちなイメージ • Linuxのプロセススケジューリング • Sleepコマンドの実際 • まとめ 11
まとめ • Sleepコマンドは少なくとも引数で指定した秒数後に終了する • システムの負荷が高いときなどに終了までの時間が延びがち • システム内のすべてのスリープ処理に同じことがいえる • ちょうど指定した秒数後に終了するという前提を置くべきではない 12