Prevent golang to set the non-block flag on ptmx open to avoid 100% CPU usage on reads (#53)

Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net>
1 file changed
tree: 320320225a749c8246443de1ce42f27e1ed24210
  1. .gitignore
  2. License
  3. README.md
  4. doc.go
  5. ioctl.go
  6. ioctl_bsd.go
  7. mktypes.bash
  8. pty_darwin.go
  9. pty_dragonfly.go
  10. pty_freebsd.go
  11. pty_linux.go
  12. pty_unsupported.go
  13. run.go
  14. types.go
  15. types_dragonfly.go
  16. types_freebsd.go
  17. util.go
  18. ztypes_386.go
  19. ztypes_amd64.go
  20. ztypes_arm.go
  21. ztypes_arm64.go
  22. ztypes_dragonfly_amd64.go
  23. ztypes_freebsd_386.go
  24. ztypes_freebsd_amd64.go
  25. ztypes_freebsd_arm.go
  26. ztypes_mipsx.go
  27. ztypes_ppc64.go
  28. ztypes_ppc64le.go
  29. ztypes_s390x.go
README.md

pty

Pty is a Go package for using unix pseudo-terminals.

Install

go get github.com/kr/pty

Example

package main

import (
	"github.com/kr/pty"
	"io"
	"os"
	"os/exec"
)

func main() {
	c := exec.Command("grep", "--color=auto", "bar")
	f, err := pty.Start(c)
	if err != nil {
		panic(err)
	}

	go func() {
		f.Write([]byte("foo\n"))
		f.Write([]byte("bar\n"))
		f.Write([]byte("baz\n"))
		f.Write([]byte{4}) // EOT
	}()
	io.Copy(os.Stdout, f)
}