Title: `_remote_debugging`: `get_child_pids()` iterates all processes four times · Issue #156060 · python/cpython · GitHub
Open Graph Title: `_remote_debugging`: `get_child_pids()` iterates all processes four times · Issue #156060 · python/cpython
X Title: `_remote_debugging`: `get_child_pids()` iterates all processes four times · Issue #156060 · python/cpython
Description: Bug report Bug description: Found while trying to understand the gcmon performance in #155828 (comment). We treat proc_listpids() as a number of PIDs: cpython/Modules/_remote_debugging/subprocess.c Line 305 in 10a8454 int n_pids = proc_l...
Open Graph Description: Bug report Bug description: Found while trying to understand the gcmon performance in #155828 (comment). We treat proc_listpids() as a number of PIDs: cpython/Modules/_remote_debugging/subprocess.c...
X Description: Bug report Bug description: Found while trying to understand the gcmon performance in #155828 (comment). We treat proc_listpids() as a number of PIDs: cpython/Modules/_remote_debugging/subprocess.c...
Opengraph URL: https://github.com/python/cpython/issues/156060
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_remote_debugging`: `get_child_pids()` iterates all processes four times","articleBody":"# Bug report\n\n### Bug description:\n\nFound while trying to understand the [gcmon](https://github.com/sergey-miryanov/gcmon) performance in https://github.com/python/cpython/pull/155828#issuecomment-5308330128.\n\nWe treat `proc_listpids()` as a number of PIDs:\n\nhttps://github.com/python/cpython/blob/10a84540c2c2533e31f5f0649cc4e4afdd991ba2/Modules/_remote_debugging/subprocess.c#L305\n\nhttps://github.com/python/cpython/blob/10a84540c2c2533e31f5f0649cc4e4afdd991ba2/Modules/_remote_debugging/subprocess.c#L320\n\nhttps://github.com/python/cpython/blob/10a84540c2c2533e31f5f0649cc4e4afdd991ba2/Modules/_remote_debugging/subprocess.c#L335\n\n...but it returns a number of bytes:\n\nhttps://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/libsyscall/wrappers/libproc/libproc.c#L62-L73\n\n`sizeof(pid_t) == 4`, so it does 4x times more work than it needs to be.\n\nThis was changed in #144648.\n\n## Reproduction\n\n```bash\n2026-08-19T18:53:44.066591000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main f40043e*?) % ps axlww | wc -l\n 996\n2026-08-19T18:53:46.142930000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main f40043e*?) % sudo dtrace -q -n 'pid$target::proc_pidinfo:entry { @ = count(); }' -c \"./python.exe repro.py\"\n\n 3996\n```\n\nfor\n\n```python\nimport _remote_debugging, os\n_remote_debugging.get_child_pids(os.getpid(), recursive=True)\n```\n\n## Fix\n\nI believe the simplest fix should be along the lines of:\n\n```c\nint n_pids = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0) / sizeof(pid_t);\n...\nint actual = proc_listpids(PROC_ALL_PIDS, 0, pid_list,\n buffer_size * sizeof(pid_t)) / sizeof(pid_t);\n```\n\n(not exactly like that because `proc_listpids()` can return `-1`).\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156061\n* gh-156069\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/maurycy","@type":"Person","name":"maurycy"},"datePublished":"2026-08-19T17:05:47Z","url":"https://github.com/python/cpython/issues/156060"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f32d99f3-73b1-d898-6805-ed19b667e082 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D33A:16E4ED:AFE4F9:DCAD8F:6B022019 |
| html-safe-nonce | 1bec07631f994dc5fad034add078ade9c09b7194f60c7f5359127f6ae5362487 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzNBOjE2RTRFRDpBRkU0Rjk6RENBRDhGOjZCMDIyMDE5IiwidmlzaXRvcl9pZCI6IjM3MTQwMzM1MjYwMzE2NTQ5MzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4f84f068a057d618310c2b223cdc3c12d8ad6a37ae7692b27a06c8afc7942db3 |
| hovercard-subject-tag | issue:5195204448 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156060/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04d9fe8df88bbb98c2feae9ed310a1f5e01c9e4978e853484054615ad1fb8ebd/python/cpython/issues/156060 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04d9fe8df88bbb98c2feae9ed310a1f5e01c9e4978e853484054615ad1fb8ebd/python/cpython/issues/156060 |
| og:image:alt | Bug report Bug description: Found while trying to understand the gcmon performance in #155828 (comment). We treat proc_listpids() as a number of PIDs: cpython/Modules/_remote_debugging/subprocess.c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maurycy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width