func GetInfoForPid()

in metric/system/process/process_aix.go [68:112]


func GetInfoForPid(_ resolve.Resolver, pid int) (ProcState, error) {
	info := C.struct_procsinfo64{}
	cpid := C.pid_t(pid)

	num, err := C.getprocs(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, nil, 0, &cpid, 1)
	if err != nil {
		return ProcState{}, fmt.Errorf("error in getprocs: %w", err)
	}
	if num != 1 {
		return ProcState{}, syscall.ESRCH
	}

	state := ProcState{}
	state.Pid = opt.IntWith(pid)

	state.Name = C.GoString(&info.pi_comm[0])
	state.Ppid = opt.IntWith(int(info.pi_ppid))
	state.Pgid = opt.IntWith(int(info.pi_pgrp))

	switch info.pi_state {
	case C.SACTIVE:
		state.State = Running
	case C.SIDL:
		state.State = Idle
	case C.SSTOP:
		state.State = Stopped
	case C.SZOMB:
		state.State = Zombie
	case C.SSWAP:
		state.State = Sleeping
	default:
		state.State = Unknown
	}

	// Get process username. Fallback to UID if username is not available.
	uid := strconv.Itoa(int(info.pi_uid))
	userID, err := user.LookupId(uid)
	if err == nil && userID.Username != "" {
		state.Username = userID.Username
	} else {
		state.Username = uid
	}

	return state, nil
}