Created
December 8, 2017 00:13
-
-
Save 17twenty/bd60caaffe9640421835b0d72e02f1cb to your computer and use it in GitHub Desktop.
Sig demo
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" | |
"log" | |
"os" | |
"os/signal" | |
"strconv" | |
"syscall" | |
) | |
func main() { | |
sigs := make(chan os.Signal, 1) | |
signal.Notify(sigs, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGINT) | |
pid := os.Getpid() | |
fmt.Println("Send a SIGUSR1 or SIGUSR2 to PID", strconv.Itoa(pid), "to BUY 100 or SELL 100 of model portfolio") | |
fmt.Println("SIGINT will report portfolio") | |
fmt.Println("e.g. $ kill -SIGUSR1", strconv.Itoa(pid)) | |
fmt.Println("CTRL-C to terminate") | |
// Buy/Sell loop | |
for { | |
sig := <-sigs | |
switch sig { | |
case syscall.SIGUSR1: | |
fmt.Println("Buying 100 of model portfolio") | |
case syscall.SIGUSR2: | |
fmt.Println("Selling 100 of model portfolio") | |
case syscall.SIGINT: | |
fmt.Println("Portfolio is X") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment