Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/signal: ignoring SIGTTIN and reading os.Stdin.Read fails badly #5572

Closed
gopherbot opened this issue May 28, 2013 · 7 comments
Closed

os/signal: ignoring SIGTTIN and reading os.Stdin.Read fails badly #5572

gopherbot opened this issue May 28, 2013 · 7 comments

Comments

@gopherbot
Copy link

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)
}
@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 2:

Labels changed: added priority-later, go1.2maybe, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 3:

Labels changed: added feature.

@robpike
Copy link
Contributor

robpike commented Aug 30, 2013

Comment 4:

Not for 1.2.

Labels changed: removed go1.2maybe.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 5:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 6:

Labels changed: removed feature.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 7:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 8:

Labels changed: added repo-main.

@mikioh mikioh changed the title syscall: ignoring SIGTTIN and reading os.Stdin.Read fails badly runtime: ignoring SIGTTIN and reading os.Stdin.Read fails badly Jan 30, 2015
@mikioh mikioh changed the title runtime: ignoring SIGTTIN and reading os.Stdin.Read fails badly os/signal: ignoring SIGTTIN and reading os.Stdin.Read fails badly Feb 16, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants