arblant
firefox-vpn-client / core / internal / desktop / programs_linux.go
programs_linux.go30 lines · 689 B
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package desktop

import (
	"os"
	"strconv"
	"strings"
)

// listsPrograms: runningPrograms works here.
const listsPrograms = true

// listProcesses is the executable of each of this user's processes, from
// /proc; another user's is not readable and is left out, as are kernel
// threads.
func listProcesses() ([]string, error) {
	entries, err := os.ReadDir("/proc")
	if err != nil {
		return nil, err
	}
	var paths []string
	for _, e := range entries {
		if _, err := strconv.Atoi(e.Name()); err != nil {
			continue
		}
		if path, err := os.Readlink("/proc/" + e.Name() + "/exe"); err == nil {
			paths = append(paths, strings.TrimSuffix(path, " (deleted)"))
		}
	}
	return paths, nil
}