wavetermdev/waveterm · error
procinfo: too few fields in stat for pid %d
Error message
procinfo: too few fields in stat for pid %d
What it means
After stripping the comm field, /proc/<pid>/stat must contain at least 22 whitespace-separated fields for the parser to extract ppid, utime, stime, num_threads, and rss (it needs rest[0..21]). Fewer fields means the stat record was truncated or structurally different from what the kernel provides.
Source
Thrown at pkg/util/procinfo/procinfo_linux.go:85
if lp < 0 || rp < 0 || rp <= lp {
return nil, fmt.Errorf("procinfo: malformed stat for pid %d", pid)
}
pidStr := strings.TrimSpace(s[:lp])
comm := s[lp+1 : rp]
rest := strings.Fields(s[rp+1:])
// rest[0] = field 3 (state), rest[1] = field 4 (ppid), ...
// Fields after comm are numbered starting at 3, so rest[i] = field (i+3).
// We need:
// rest[0] = field 3 state
// rest[1] = field 4 ppid
// rest[11] = field 14 utime
// rest[12] = field 15 stime
// rest[17] = field 20 num_threads
// rest[21] = field 24 rss (pages)
if len(rest) < 22 {
return nil, fmt.Errorf("procinfo: too few fields in stat for pid %d", pid)
}
parsedPid, err := strconv.ParseInt(pidStr, 10, 32)
if err != nil {
return nil, fmt.Errorf("procinfo: parse pid: %w", err)
}
statusChar := rest[0]
status, ok := LinuxStatStatus[statusChar]
if !ok {
status = "unknown"
}
info := &ProcInfo{
Pid: int32(parsedPid),
Command: comm,
Status: status,
CpuUser: -1,View on GitHub (pinned to a4447c1563)
Solutions
- Retry the read once — transient truncation during process teardown is possible
- Verify /proc/<pid>/stat has ~52 fields (cat /proc/<pid>/stat | wc -w)
- If on a custom/embedded kernel, confirm its procfs stat layout matches mainline field ordering
- Fix test fixtures to include at least 24 stat fields
Example fix
// before
if len(rest) < 22 {
return nil, fmt.Errorf("procinfo: too few fields in stat for pid %d", pid)
}
// after: parse what is available instead of failing
if len(rest) < 22 {
return info, nil // partial info; fields default to -1
} Defensive patterns
Strategy: retry
Validate before calling
// verify field count before dependent processing
data, _ := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))
if strings.Count(string(data), " ") < 24 {
// truncated/insufficient stat; avoid processing
} Try / catch
_, err := procinfo.GetProcInfo(ctx, nil, pid)
if err != nil && strings.Contains(err.Error(), "too few fields") {
// retry after a short delay; persistent failure means kernel/fixture problem
} Prevention
- Use mainline Linux kernels or verify procfs layout on custom kernels
- Include >= 24 fields in test stat fixtures
- Retry transient truncations instead of failing the poll cycle
- Sanity-check 'wc -w /proc/<pid>/stat' (~52) in deployment diagnostics
When it happens
Trigger: A truncated read of a stat file during process exit; reading a fake/fixture stat file with too few columns; an exotic kernel whose stat format omits trailing fields.
Common situations: Custom kernels or stripped-down embedded Linux builds with divergent procfs; unit-test fixtures missing fields; corrupted procfs output from virtualization.
Related errors
- procinfo: malformed stat for pid %d
- procinfo: parse pid: %w
- procinfo: process not found
- procinfo: read %s: %w
- procinfo: Uid line not found in %s
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/352b143b2f2d2439.
Report an issue: GitHub.