Skip to content

Some problem of ListPID #33

@LiSheep

Description

@LiSheep

Hello, I found that the 'ListPID()' function will show all of processes include sub-threads. And this may not suit for someone. I found source code in 'top' command, it only read dir in /proc which is digit & isDir, this will not list the pid which is not main thread. I give my simple code under below:

func ListProgram(path string) ([]uint64, error) {
        pids := make([]uint64, 0, 20)
	infos, err := ioutil.ReadDir(path)
	if err != nil {
		return  nil, err
	}
	for _, info := range(infos) {
		pid, err := strconv.ParseUint(info.Name(), 10, 64)
		if err != nil {
			continue
		}
		pids = append(pids, pid)
	}
	return pids, nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions