发送/捕获 SIGTERM 的 Win32 API 模拟 [英] Win32 API analog of sending/catching SIGTERM

查看:35
本文介绍了发送/捕获 SIGTERM 的 Win32 API 模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 POSIX OS 下有信号 API 允许发送信号给进程以关闭它使用 kill,您可以使用 sigaction 捕获它并执行您需要的操作;

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆