-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Go programs don't respond to SIGTSTP (ctl+Z) #776
Labels
Comments
Works on darwin/amd64: package main import ( "fmt" "syscall" "os/signal" ) func main() { for sig := range signal.Incoming { fmt.Printf("Got signal: %s\n", sig) if usig,ok := sig.(signal.UnixSignal); ok { if usig == syscall.SIGTSTP { fmt.Printf("Suspending\n") syscall.Kill(syscall.Getppid(), syscall.SIGTSTP) } } } } |
The following works on darwin/amd64: package main import ( "fmt" "syscall" "os/signal" ) func main() { for sig := range signal.Incoming { fmt.Printf("Got signal: %s\n", sig) if usig,ok := sig.(signal.UnixSignal); ok { if usig == syscall.SIGTSTP { fmt.Printf("Suspending\n") syscall.Kill(syscall.Getpid(), syscall.SIGSTOP) } } } } Essentially, you can catch the TSTP signal and then send yourself the STOP signal. I don't know how this will interact with things like time.Sleep, as I don't know if the runtime is equipped to handle being forcibly stopped, but in my trivial case it appears to work. While this is not an automated, built-in solution, it will emulate the behavior that you are seeking. (sorry about the extra comment, I pasted an older version of the code and managed to send it instead of repasting) |
The issue is that we want to permit Go programs to catch SIGTSTP. However, if the program does not catch SIGTSTP, then we want it to have its default effect. So a partial answer would be that if sigsend returns false for SIGTSTP, we should remove the handler and reraise the signal. Then we should reinstall the signal handler, so that the obscure case of a later call to runtime.Siginit will work correctly. However, I don't know a natural way to make this work for a program that calls runtime.Siginit (typically via importing os/signal). Most programs that catch signals do not actually want to catch SIGTSTP, but some do. The best idea I can think of right now is that we could require a program which handles SIGTSTP to call a function in the os/signal package to enable it. We should probably handle SIGTTIN and SIGTTOU the same way we handle SIGTSTP. |
This issue was closed by revision 807605d. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: