2015-09-18 16:39:12 -04:00
|
|
|
// +build linux freebsd
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package fileutils // import "github.com/docker/docker/pkg/fileutils"
|
2015-09-18 16:39:12 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2015-09-18 16:39:12 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetTotalUsedFds Returns the number of used File Descriptors by
|
|
|
|
// reading it via /proc filesystem.
|
|
|
|
func GetTotalUsedFds() int {
|
|
|
|
if fds, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/fd", os.Getpid())); err != nil {
|
|
|
|
logrus.Errorf("Error opening /proc/%d/fd: %s", os.Getpid(), err)
|
|
|
|
} else {
|
|
|
|
return len(fds)
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|