发送/捕获SIGTERM的Win32 API模拟 [英] Win32 API analog of sending/catching SIGTERM
问题描述
在POSIX OS下,有信号API,该API允许发送信号进行处理以将其关闭 杀死就可以了,您可以立即采取行动并做您需要的事;
Under POSIX OS there is signal API that allows to send a signal to process to shut it down with kill and you can catch it with sigaction and do what you need;
但是,Win32不是POSIX系统,所以:
However, Win32 is not POSIX system, so:
- 如何处理关闭事件,例如任务管理器"中的结束进程"?
- 用于向Win32应用程序发送关闭信号的标准API是什么?
我不是在谈论GUI,我是在谈论应该完全关闭的TCP/IP服务器. 不像Windows服务一样运行.
I'm not talking about GUI, I'm talking about TCP/IP server that should be nicely shutdown. that does not run like windows service.
推荐答案
您在第一个创建的线程上收到一条WM_QUIT
消息.
You get a WM_QUIT
message on your first created thread.
如果不处理该问题,则会强制关闭进程.
When you don't handle that, your process is forcibly shutdown.
因此,只需在您的第一个线程中实现一个消息队列,该队列就会查找WM_QUIT
消息
So just implement a message queue in your first thread, which looks for the WM_QUIT
message
这篇关于发送/捕获SIGTERM的Win32 API模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!