Sending an interrupt signal via the debugger
Hi Folks,
Working on a Go program in IntelliJ and need to test a graceful shutdown implementation. Is it possible to send an interrupt or kill signal to the program when running in the debugger?
Thanks.
请先登录再写评论。
Hi David,
Unless I'm missing something, simply clicking on Stop button while debugging should do the trick:
This terminates the application. Is this something you were looking for?
Thanks for the reply.
Here's my impression: when you click that Stop button, it does indeed send a signal to the code, but it also stops the debugger. So, for example, if I have a break point in a location intended to fire when an interrupt or kill signal is detected, the program doesn't break because I have asked the debugger to actually stop operating. In effect, I am looking for something just shy of clicking this Stop button, as I need the debugger operational while the program gracefully cleans up.
I have tested this with the stop button, and I am getting mixed results. For example, I currently have logging at three locations where signals are intercepted: two in sub processes and one at the very to of the calling structure. In just about all cases, the sub processes will write their log entries, but the top sometimes will not (but not always). Difficult to test with such uncertainty.
Thanks again.
I see. In such a case, probably what you'd need to do is to kill a specific process responsible for the application itself. The approach would look something like this:
pgrep -f "dlv --listen")pgrep -P *PID_from_step_2*)kill -INT *PID_from_step_3*- this will kill the subprocess we found at step 3 (your actual application launched in Delve), but the debugger should still be running.Does this do the trick?
Thanks, and I thought about that. Maybe this is an edge case, but it seems like this would be much more graceful as a feature in the debugger.
I appreciate these commands. I'll play around with the, and reply with any feedback.
Best.
OK, this seemed to work, but I had to go one step further down (I'm on a Mac, so it may be relevant). The break point fired:
This is a bit easier:
kill -s INT $(pgrep ___run)Hi cajund ! Thank you for trying this. Indeed, this is somewhat of an edge case, but I understand where this might come in handy, so I created a feature request on your behalf to add functionality to stop the application without stopping the debugger. Please follow the case here - GO-19026. I can't promise any changes will be implemented, however, we'll monitor if there is any demand for such a feature to be added from other users, and this will be considered when working on the future iterations of the existing functionality..
Thanks Vadym,
I was successful in testing my code using the above command line, and it worked as expected. I was able to tweak the code to perform as needed, and seeing the breakpoints fire was instrumental.
Appreciate all your help, and adding that ticket on my behalf.
All the best!