AllThreads returns a list of all currently available threads for PID.
(pid int)
| 36 | |
| 37 | // AllThreads returns a list of all currently available threads for PID. |
| 38 | func (fs FS) AllThreads(pid int) (Procs, error) { |
| 39 | taskPath := fs.proc.Path(strconv.Itoa(pid), "task") |
| 40 | d, err := os.Open(taskPath) |
| 41 | if err != nil { |
| 42 | return Procs{}, err |
| 43 | } |
| 44 | defer d.Close() |
| 45 | |
| 46 | names, err := d.Readdirnames(-1) |
| 47 | if err != nil { |
| 48 | return Procs{}, fmt.Errorf("%w: could not read %q: %w", ErrFileRead, d.Name(), err) |
| 49 | } |
| 50 | |
| 51 | t := Procs{} |
| 52 | for _, n := range names { |
| 53 | tid, err := strconv.ParseInt(n, 10, 64) |
| 54 | if err != nil { |
| 55 | continue |
| 56 | } |
| 57 | |
| 58 | t = append(t, Proc{PID: int(tid), fs: FS{fsi.FS(taskPath), fs.isReal}}) |
| 59 | } |
| 60 | |
| 61 | return t, nil |
| 62 | } |
| 63 | |
| 64 | // Thread returns a process for a given PID, TID. |
| 65 | func (fs FS) Thread(pid, tid int) (Proc, error) { |