From d6fa6d1542e1c955cf3917f62d532535b0b6dd7e Mon Sep 17 00:00:00 2001 From: AmiPoke Date: Wed, 14 Oct 2026 13:40:27 +0200 Subject: [PATCH] Prozessnamen mit abgeschnittenem UTF-8 tolerant lesen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der Kernel kürzt comm byteweise auf 15 Bytes; ein halber Umlaut löste UnicodeDecodeError aus und beendete den Dienst. Co-Authored-By: Claude Opus 5.5 --- src/ramscreen/meminfo.py | 5 +++-- tests/test_meminfo.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ramscreen/meminfo.py b/src/ramscreen/meminfo.py index 43d2ab1..5207f76 100644 --- a/src/ramscreen/meminfo.py +++ b/src/ramscreen/meminfo.py @@ -63,12 +63,13 @@ def _app_name(pid_dir: Path) -> str: return name except OSError: pass - return (pid_dir / "comm").read_text().strip() + # errors="replace": der Kernel kürzt comm byteweise, auch mitten in einem UTF-8-Zeichen + return (pid_dir / "comm").read_text(errors="replace").strip() def _field_kb(path: Path, field: str) -> int | None: try: - for line in path.read_text().splitlines(): + for line in path.read_text(errors="replace").splitlines(): if line.startswith(field): return int(line.split()[1]) except OSError: diff --git a/tests/test_meminfo.py b/tests/test_meminfo.py index 65c342f..aadaa33 100644 --- a/tests/test_meminfo.py +++ b/tests/test_meminfo.py @@ -103,6 +103,16 @@ def test_top_apps_versionsnummer_als_dateiname_nutzt_comm(tmp_path: Path): assert top_apps(5, tmp_path) == [App("claude", 500 * 1024)] +def test_top_apps_abgeschnittenes_utf8_in_comm_und_status(tmp_path: Path): + # Der Kernel kürzt comm byteweise auf 15 Bytes – auch mitten in einem Umlaut + make_proc(tmp_path, 1, exe=None, comm=None, rss_kb=100) + (tmp_path / "1" / "comm").write_bytes(b"abcdefghijklmn\xc3\n") + (tmp_path / "1" / "status").write_bytes(b"Name:\tabcdefghijklmn\xc3\nVmRSS:\t100 kB\n") + apps = top_apps(5, tmp_path) + assert [a.size for a in apps] == [100 * 1024] + assert apps[0].name.startswith("abcdefghijklmn") + + def test_top_apps_ueberspringt_kernel_threads_und_verschwundene(tmp_path: Path): # Kernel-Thread: kein exe, leeres smaps_rollup, kein VmRSS make_proc(tmp_path, 2, exe=None, comm="kworker/0:1", smaps_text="")