tclose.nim 506 B

12345678910111213141516171819202122232425
  1. discard """
  2. exitcode: 0
  3. """
  4. when defined(linux):
  5. import osproc, os
  6. proc countFds(): int =
  7. result = 0
  8. for i in walkDir("/proc/self/fd"):
  9. result += 1
  10. let initCount = countFds()
  11. let p = osproc.startProcess("echo", options={poUsePath})
  12. assert countFds() == initCount + 3
  13. p.close
  14. assert countFds() == initCount
  15. let p1 = osproc.startProcess("echo", options={poUsePath})
  16. discard p1.inputStream
  17. assert countFds() == initCount + 3
  18. p.close
  19. assert countFds() == initCount