Skip to content

Instantly share code, notes, and snippets.

@17twenty 17twenty/sigdemo.go
Created Dec 8, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.