mattn / go-tty

MIT License
211 stars 18 forks source link

tty.Open() suspends process when in background (linux) #26

Closed ThisGuyCodes closed 5 years ago

ThisGuyCodes commented 5 years ago

tty.Open() causes the calling process to suspend with SIGTTOU on Linux if the caller is not in the foreground. Specifically the ioctl termios write is what hangs.

Ideally this would instead return an error.

I attempted a prototype to catch this signal with signal.Notify() but it seems the signal isn't actually being sent until the process is in the foreground? Not sure.

Alternatively is there a way to predict that this will happen? Some way of reading if the process is in the foreground?

mattn commented 5 years ago

Can you provide small code reproducible?

ThisGuyCodes commented 5 years ago
package main

import "github.com/mattn/go-tty"

func main() {
    tty.Open()
}

go run main.go &

mattn commented 5 years ago

Probably, it's not issue of go-tty, but if you want to run tasks in background, how about to ignore the signal?

 signal.Ignore(syscall.SIGTTOU)
ThisGuyCodes commented 5 years ago

On second thought, maybe it makes more sense for the calling process to be responsible for this.

I will say that it's not intuitive that Open() writes to the tty config.