Use pidfd to track processes on Linux >= 5.4

オープン
#190 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
32/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
haskell, linux

調査の方向性

まずプロセスライブラリの ProcessHandle とプロセス生成のパスから始め、次にリンクされている pidfd_open()、clone()、waitid() のリファレンスと、リンクされている Rust 実装を読みます。この issue では、Linux 5.4+ で pidfd を追跡し、それをより安全なプロセス待機に使用することが説明されています。done では、PID の再利用による競合を避けつつ、既存の動作を維持する必要があります。

索引モデルが issue の本文から書いたものです。

説明

Background:

The problem Pids in ProcessHandles is that on most system they are limited to 2^16 many by default. If you spawn many short-lived processes quickly, the pid namespace can wrap around and you will accidentally waitForProcess (wait()) on the wrong process, or terminateProcess the wrong one.

Linux 5.4 solves this with pidfds (which are per-process, and 32-bit many). They can point to zombie processes so they will never accidentally point to a different process.

The process library could use them on newer Linux by simply tracking the pidfd in a Maybe field inside ProcessHandle.

  • After being spawned, a pid can be converted to a pidfd using pidfd_open() -- but this is still slightly racy, and better is to get it atomically directly from clone(). But it's an easy migration path that's a strict improvement already.
  • pidfds can be waited on with select(), epoll() and so on, which means we can use the GHC IO manager to wait for them more efficiently than with the usual waitForProcess.

This Rust library https://github.com/pop-os/pidfd shows how you can wait for a program to finish using waitid().

主要言語
Haskell
スター
91
フォーク
93
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

haskell/process のほかの issue

haskell/process の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。