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="")