MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / isKernelThread

Method isKernelThread

lib/process_validator.go:443–464  ·  view source on GitHub ↗

isKernelThread checks if a process is a kernel thread (Linux-specific)

(pid int)

Source from the content-addressed store, hash-verified

441
442// isKernelThread checks if a process is a kernel thread (Linux-specific)
443func (pv *ProcessValidator) isKernelThread(pid int) (bool, error) {
444 if runtime.GOOS != "linux" {
445 return false, nil
446 }
447
448 statFile := fmt.Sprintf("/proc/%d/stat", pid)
449 data, err := os.ReadFile(statFile)
450 if err != nil {
451 return false, fmt.Errorf("cannot read process stat: %v", err)
452 }
453
454 statFields := strings.Fields(string(data))
455 if len(statFields) < 3 {
456 return false, fmt.Errorf("invalid stat file format")
457 }
458
459 // Field 2 is the command name, kernel threads are typically in brackets like [kthreadd]
460 cmdName := statFields[1]
461 isKernel := strings.HasPrefix(cmdName, "[") && strings.HasSuffix(cmdName, "]")
462
463 return isKernel, nil
464}
465
466// ValidatePIDList validates a list of PIDs and returns detailed error information
467func (pv *ProcessValidator) ValidatePIDList(pids []int) map[int]error {

Callers 1

ValidatePIDMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected