Created
January 17, 2018 18:14
-
-
Save fd0/78060d2d8763f77e7ec3cbbfbcbf6105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"os/signal" | |
"syscall" | |
) | |
func main() { | |
cmd := exec.Command("ssh", "localhost", "echo 'remote: start'; sleep 60; echo 'remote: done'") | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
cmd.SysProcAttr = &syscall.SysProcAttr{ | |
Setsid: true, | |
} | |
ch := make(chan os.Signal) | |
signal.Notify(ch, syscall.SIGINT) | |
go func() { | |
for sig := range ch { | |
fmt.Printf("main: signal received: %v\n", sig) | |
} | |
}() | |
signal.Ignore(syscall.SIGINT) | |
err := cmd.Start() | |
if err != nil { | |
fmt.Printf("main: start returned err: %v\n", err) | |
} | |
signal.Notify(ch, syscall.SIGINT) | |
err = cmd.Wait() | |
if err != nil { | |
fmt.Printf("main: wait returned err: %v\n", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment