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

Method FileDescriptorsLen

proc.go:245–265  ·  view source on GitHub ↗

FileDescriptorsLen returns the number of currently open file descriptors of a process.

()

Source from the content-addressed store, hash-verified

243// FileDescriptorsLen returns the number of currently open file descriptors of
244// a process.
245func (p Proc) FileDescriptorsLen() (int, error) {
246 // Use fast path if available (Linux v6.2): https://github.com/torvalds/linux/commit/f1f1f2569901
247 if p.fs.isReal {
248 stat, err := os.Stat(p.path("fd"))
249 if err != nil {
250 return 0, err
251 }
252
253 size := stat.Size()
254 if size > 0 {
255 return int(size), nil
256 }
257 }
258
259 fds, err := p.fileDescriptors()
260 if err != nil {
261 return 0, err
262 }
263
264 return len(fds), nil
265}
266
267// MountStats retrieves statistics and configuration for mount points in a
268// process's namespace.

Callers 1

TestFileDescriptorsLenFunction · 0.80

Calls 3

pathMethod · 0.95
fileDescriptorsMethod · 0.95
StatMethod · 0.45

Tested by 1

TestFileDescriptorsLenFunction · 0.64