by viriketo:
On linux x86_64, go 1.1:
I want a process to be able to read on Stdin, but if set to background, I want it not
stopped.
Currently, os.Stdin.Read() goes into infinite loop, if I ignore the SIGTTIN signal
received when reading on a tty while the process is in background.
os.Stdin.Read() calls the read() syscall; if the process is in background, it's
interrupted with ERESTART and the process receives SIGTTIN; that should stop the
process. If I ignore the signal, the process doesn't stop, but os.Stdin.Read() calls
read() in a loop due to ERESTART, getting SIGTTIN again, and so on (max cpu usage).
How can I make a process that doesn't stop when sent to background, if I want it also to
be able to read stdin (when foreground)?
Code to reproduce it (run with &):
-----------------
package main
import (
"os"
"os/signal"
"syscall"
)
func main() {
ignore := make(chan os.Signal)
signal.Notify(ignore, syscall.SIGTTIN)
v := make([]byte, 10)
os.Stdin.Read(v)
}
by viriketo:
On linux x86_64, go 1.1: I want a process to be able to read on Stdin, but if set to background, I want it not stopped. Currently, os.Stdin.Read() goes into infinite loop, if I ignore the SIGTTIN signal received when reading on a tty while the process is in background. os.Stdin.Read() calls the read() syscall; if the process is in background, it's interrupted with ERESTART and the process receives SIGTTIN; that should stop the process. If I ignore the signal, the process doesn't stop, but os.Stdin.Read() calls read() in a loop due to ERESTART, getting SIGTTIN again, and so on (max cpu usage). How can I make a process that doesn't stop when sent to background, if I want it also to be able to read stdin (when foreground)? Code to reproduce it (run with &): ----------------- package main import ( "os" "os/signal" "syscall" ) func main() { ignore := make(chan os.Signal) signal.Notify(ignore, syscall.SIGTTIN) v := make([]byte, 10) os.Stdin.Read(v) }