I run a program in Go that continuously sends data after reading the /proc/stat file. Using ioutil.ReadFile("/proc/stat") After starting about 14 hours, I got an error: too many files open /proc/stat Click here for the code snippet.
I doubt that defer f.Close ignored by Go sometimes or skips it.
Code snippet (in case play.golang.org dies earlier than stackoverflow.com):
package main import ("fmt";"io/ioutil") func main() { for { fmt.Println("Hello, playground") fData,err := ioutil.ReadFile("/proc/stat") if err != nil { fmt.Println("Err is ",err) } fmt.Println("FileData",string(fData)) } }
source share