Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
シェルのジョブ
Search
Satoru Takeuchi
PRO
February 23, 2025
Technology
1
59
シェルのジョブ
以下動画のテキストです。
https://youtu.be/LvuQqQvtork
Satoru Takeuchi
PRO
February 23, 2025
Tweet
Share
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
APIとABIの違い
sat
PRO
5
54
ファイルシステムへのアクセス方法
sat
PRO
0
22
ファイルシステム
sat
PRO
1
23
低レイヤソフトウェア技術者が YouTuberとして食っていこうとした話
sat
PRO
7
6.1k
ポーリングと割り込み
sat
PRO
1
78
Rook: Intro and Deep Dive With Ceph
sat
PRO
1
140
会社員しながら本を書いてきた知見の共有
sat
PRO
3
880
デバイスにアクセスするデバイスファイル
sat
PRO
1
60
ファイルシステムのデータを ブロックデバイスへの操作で変更
sat
PRO
1
48
Other Decks in Technology
See All in Technology
バッチ処理で悩むバックエンドエンジニアに捧げるAWS Glue入門
diggymo
3
120
複数サービスを支えるマルチテナント型Batch MLプラットフォーム
lycorptech_jp
PRO
0
160
絶対に失敗できないキャンペーンページの高速かつ安全な開発、WINTICKET × microCMS の開発事例
microcms
0
390
衝突して強くなる! BLUE GIANTと アジャイルチームの共通点とは ― いきいきと活気に満ちたグルーヴあるチームを作るコツ ― / BLUE GIANT and Agile Teams
naitosatoshi
0
310
Grafana MCPサーバーによるAIエージェント経由でのGrafanaダッシュボード動的生成
hamadakoji
1
1.3k
allow_retry と Arel.sql / allow_retry and Arel.sql
euglena1215
1
150
開発者を支える Internal Developer Portal のイマとコレカラ / To-day and To-morrow of Internal Developer Portals: Supporting Developers
aoto
PRO
1
290
Function Body Macros で、SwiftUI の View に Accessibility Identifier を自動付与する/Function Body Macros: Autogenerate accessibility identifiers for SwiftUI Views
miichan
2
170
AI時代に非連続な成長を実現するエンジニアリング戦略
sansantech
PRO
3
1.1k
ライブサービスゲームQAのパフォーマンス検証による品質改善の取り組み
gree_tech
PRO
0
540
なぜテストマネージャの視点が 必要なのか? 〜 一歩先へ進むために 〜
moritamasami
0
110
個人CLAUDE.md紹介と設定から学んだこと/introduce-my-claude-md
shibayu36
0
200
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
520
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
It's Worth the Effort
3n
187
28k
Imperfection Machines: The Place of Print at Facebook
scottboms
268
13k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
How to train your dragon (web standard)
notwaldorf
96
6.2k
How to Think Like a Performance Engineer
csswizardry
26
1.9k
Transcript
シェルのジョブ Feb. 23rd, 2025 Satoru Takeuchi X: satoru_takeuchi 1
シェルのジョブ • シェル上での1つのコマンド、またはパイプで繋がれた一連のプロセス • 2種類ある ◦ フォアグラウンドジョブ : 実行時に末尾に”&”を付けない(e.g. ps
ajx | less) ▪ 端末に直接アクセスできる ▪ セッションの中で常に 1つ ◦ バックグラウンドジョブ : 実行時に末尾に”&”を付ける(e.g. go build &) ▪ バックグラウンド(裏側)で実行 ▪ 端末に直接アクセスできない • アクセスするとフォアグラウンドプロセスになるまで待たされる ▪ セッションの中で複数存在できる 2
プロセスグループ 3 • カーネルの機能 • シェルのセッションはプロセスグループを使って実装している ◦ フォアグラウンドジョブ => フォアグラウンドプロセスグループ
◦ バックグラウンドジョブ => バックグラウンドプロセスグループ • パイプラインの最初のプロセスをプロセスグループリーダーと呼ぶ ◦ プロセスグループリーダーは端末の入出力を直接受け取る • プロセスグループごとに固有のID、プロセスグループIDが対応する ◦ プロセスグループIDはプロセスグループリーダーの PIDと等しい
セッションとジョブの関係 4 セッション プロセスグループ(ジョブ)1 (バックグラウンド) プロセスグループ(ジョブ)2 (フォアグラウンド) ps aux less
端末 go build bash 生成 生成&パイプでつなげる アクセス可 フォアグラウンド になるまで アクセスを待たさ れる
例 • “go build”はバックグラウンドジョブ(プロセスグループ)として実行 • “ps aux | less”はフォアグラウンドジョブ(プロセスグループ)として実行 5
$ go build & $ ps ajx | less PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND ... 19261 19262 19262 19262 pts/0 19653 Ss 1000 0:00 -bash ... 19262 19653 19653 19262 pts/0 19653 R+ 1000 0:00 ps ajx 19262 19654 19653 19262 pts/0 19653 S+ 1000 0:00 less ...
プロセスグループとシグナル • シグナルはプロセスグループに送れる ◦ プロセスグループ内の全プロセスにシグナルを送る ◦ “kill”コマンドの場合、例えば ”kill -100”を実行するとプロセスグループ (IDは100)にシグナルを送る
• 疑似端末上で”C-c”を押すとフォアグラウンドプロセスグループにSIGINTシグナル を送る ◦ バックグラウンドプロセスグループには送らないのでバックグラウンドプロセスは残る 6
まとめ • シェルのセッションにはジョブという概念がある • ジョブはカーネルのプロセスグループという機能によって実現している ◦ フォアグラウンドジョブ => フォアグラウンドプロセスグループ ▪
端末に直接アクセスできる ◦ バックグラウンドジョブ => バックグラウンドプロセスグループ ▪ 端末にアクセスすると待たされる • プロセスグループにシグナルを送信すると、所属する全プロセスにシグナルを送信 する 7