4

I want to capture the OS signal and do some exit jobs when I terminate the vscode golang debugger.

I have code as below:

sigalChan := make(chan os.Signal, 1)
signal.Notify(sigalChan, syscall.SIGINT, syscall.SIGTERM)
<-sigalChan
doSomeJobs()

but it doesn't work. Anyone can tell me how to figure it out? Maybe the signal type is not SIGINT or SIGTERM?

zengtao321
  • 131
  • 5

1 Answers1

9

I find out a solution. Just set "console" to "integratedTerminal" in launch.json to make delve server foreground, then I can use "ctrl+c" to terminate the debugging process, and signal can be received in my program.

{
    // launch.json
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}/main.go",
            "console": "integratedTerminal"
        }
    ]
}
zengtao321
  • 131
  • 5