Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@17twenty
Created December 8, 2017 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 17twenty/bd60caaffe9640421835b0d72e02f1cb to your computer and use it in GitHub Desktop.
Save 17twenty/bd60caaffe9640421835b0d72e02f1cb to your computer and use it in GitHub Desktop.
Sig demo
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