FileDescriptorsLen returns the number of currently open file descriptors of a process.
()
| 243 | // FileDescriptorsLen returns the number of currently open file descriptors of |
| 244 | // a process. |
| 245 | func (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. |