// Copyright 2018 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 ()// Namespace represents a single namespace of a process.typeNamespacestruct { Type string// Namespace type. Inode uint32// Inode number of the namespace. If two processes are in the same namespace their inodes will match.}// Namespaces contains all of the namespaces that the process is contained in.typeNamespacesmap[string]Namespace// Namespaces reads from /proc/<pid>/ns/* to get the namespaces of which the// process is a member.func ( Proc) () (Namespaces, error) { , := os.Open(.path("ns"))if != nil {returnnil, }defer .Close() , := .Readdirnames(-1)if != nil {returnnil, fmt.Errorf("%w: failed to read contents of ns dir: %w", ErrFileRead, ) } := make(Namespaces, len())for , := range { , := os.Readlink(.path("ns", ))if != nil {returnnil, } := strings.SplitN(, ":", 2)iflen() != 2 {returnnil, fmt.Errorf("%w: namespace type and inode from %q", ErrFileParse, ) } := [0] , := strconv.ParseUint(strings.Trim([1], "[]"), 10, 32)if != nil {returnnil, fmt.Errorf("%w: inode from %q: %w", ErrFileParse, [1], ) } [] = Namespace{, uint32()} }return , 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.