//go:build linux || freebsd || darwin || openbsd

package common

import (
	
	
	
	
)

func ( context.Context,  Invoker,  int32,  ...string) ([]string, error) {
	var  []string
	if  == 0 { // will get from all processes.
		 = []string{"-a", "-n", "-P"}
	} else {
		 = []string{"-a", "-n", "-P", "-p", strconv.Itoa(int())}
	}
	 = append(, ...)
	,  := exec.LookPath("lsof")
	if  != nil {
		return []string{}, 
	}
	,  := .CommandWithContext(, , ...)
	if  != nil {
		// if no pid found, lsof returns code 1.
		if .Error() == "exit status 1" && len() == 0 {
			return []string{}, nil
		}
	}
	 := strings.Split(string(), "\n")

	var  []string
	for ,  := range [1:] {
		if len() == 0 {
			continue
		}
		 = append(, )
	}
	return , nil
}

func ( context.Context,  Invoker,  int32) ([]int32, error) {
	 := []string{"-P", strconv.Itoa(int())}
	,  := exec.LookPath("pgrep")
	if  != nil {
		return []int32{}, 
	}
	,  := .CommandWithContext(, , ...)
	if  != nil {
		return []int32{}, 
	}
	 := strings.Split(string(), "\n")
	 := make([]int32, 0, len())
	for ,  := range  {
		if len() == 0 {
			continue
		}
		,  := strconv.Atoi()
		if  != nil {
			continue
		}
		 = append(, int32())
	}
	return , nil
}