MCPcopy Create free account
hub / github.com/prometheus/procfs / AllThreads

Method AllThreads

thread.go:38–62  ·  view source on GitHub ↗

AllThreads returns a list of all currently available threads for PID.

(pid int)

Source from the content-addressed store, hash-verified

36
37// AllThreads returns a list of all currently available threads for PID.
38func (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.
65func (fs FS) Thread(pid, tid int) (Proc, error) {

Callers 3

AllThreadsFunction · 0.95
TestAllThreadsFunction · 0.80
TestThreadStatFunction · 0.80

Calls 2

NameMethod · 0.80
PathMethod · 0.45

Tested by 2

TestAllThreadsFunction · 0.64
TestThreadStatFunction · 0.64