//go:build linux package version import ( "fmt" "os" "strings" ) func processIdentityToken(pid int) (string, error) { data, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid)) if err != nil { return "", err } // The parenthesized command may contain spaces or right parentheses. The // final ") " precedes field 3; starttime is field 22 (index 19 below). end := strings.LastIndex(string(data), ") ") if end < 0 { return "", fmt.Errorf("malformed process stat for PID %d", pid) } fields := strings.Fields(string(data)[end+2:]) if len(fields) <= 19 { return "", fmt.Errorf("process stat for PID %d has %d fields", pid, len(fields)+2) } return fields[19], nil }