AllProcs returns a list of all currently available processes.
()
| 103 | |
| 104 | // AllProcs returns a list of all currently available processes. |
| 105 | func (fs FS) AllProcs() (Procs, error) { |
| 106 | d, err := os.Open(fs.proc.Path()) |
| 107 | if err != nil { |
| 108 | return Procs{}, err |
| 109 | } |
| 110 | defer d.Close() |
| 111 | |
| 112 | names, err := d.Readdirnames(-1) |
| 113 | if err != nil { |
| 114 | return Procs{}, fmt.Errorf("%w: Cannot read file: %v: %w", ErrFileRead, names, err) |
| 115 | } |
| 116 | |
| 117 | p := Procs{} |
| 118 | for _, n := range names { |
| 119 | pid, err := strconv.ParseInt(n, 10, 64) |
| 120 | if err != nil { |
| 121 | continue |
| 122 | } |
| 123 | p = append(p, Proc{PID: int(pid), fs: fs}) |
| 124 | } |
| 125 | |
| 126 | return p, nil |
| 127 | } |
| 128 | |
| 129 | // CmdLine returns the command line of a process. |
| 130 | func (p Proc) CmdLine() ([]string, error) { |