// Copyright 2022 The Prometheus Authors// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.package procfsimport (fsi)// Provide access to /proc/PID/task/TID files, for thread specific values. Since// such files have the same structure as /proc/PID/ ones, the data structures// and the parsers for the latter may be reused.// AllThreads returns a list of all currently available threads under /proc/PID.func ( int) (Procs, error) { , := NewFS(DefaultMountPoint)if != nil {returnProcs{}, }return .AllThreads()}// AllThreads returns a list of all currently available threads for PID.func ( FS) ( int) (Procs, error) { := .proc.Path(strconv.Itoa(), "task") , := os.Open()if != nil {returnProcs{}, }defer .Close() , := .Readdirnames(-1)if != nil {returnProcs{}, fmt.Errorf("%w: could not read %q: %w", ErrFileRead, .Name(), ) } := Procs{}for , := range { , := strconv.ParseInt(, 10, 64)if != nil {continue } = append(, Proc{PID: int(), fs: FS{fsi.FS(), .isReal}}) }return , nil}// Thread returns a process for a given PID, TID.func ( FS) (, int) (Proc, error) { := .proc.Path(strconv.Itoa(), "task")if , := os.Stat(); != nil {returnProc{}, }returnProc{PID: , fs: FS{fsi.FS(), .isReal}}, nil}// Thread returns a process for a given TID of Proc.func ( Proc) ( int) (Proc, error) { := FS{fsi.FS(.path("task")), .fs.isReal}if , := os.Stat(.proc.Path(strconv.Itoa())); != nil {returnProc{}, }returnProc{PID: , fs: }, nil}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.