当您关闭 c++ 时会发生什么? 控制台应用程序

发布于 2024-07-15 19:13:03 字数 95 浏览 2 评论 0 原文

我想这个问题说明了一切,但是,如果有人关闭 c++ 控制台应用程序会发生什么? 如图所示,单击顶角的“x”。 会立即关闭吗? 它会抛出某种异常吗? 这是未定义的行为吗?

I guess the question says it all, but, what happens if someone closes a c++ console app? As in, clicks the "x" in the top corner. Does it instantly close? Does it throw some sort of exception? Is it undefined behavior?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浮云落日 2024-07-22 19:13:03

使用顶角的“x”关闭 C++ 控制台应用程序会引发 CTRL_CLOSE_EVENT,如果您使用 SetConsoleCtrlHandler 函数。 在那里,您可以覆盖关闭功能并执行您想要执行的任何操作,然后仍然可以选择执行默认行为。

Closing a c++ console app with the "x" in the top corner throws an CTRL_CLOSE_EVENT which you could catch and process if you set a control handler using the SetConsoleCtrlHandler function. In there you could override the close functionality and perform whatever you wished to do, and then optionally still perform the default behavior.

酒解孤独 2024-07-22 19:13:03

我想控制台进程会被操作系统毫不客气地杀死。 如果您想捕获此事件并执行类似 SetConsoleCtrlHandler 函数就是这样做的。

另请参阅:

I imagine that the console process just gets unceremoniously killed by the OS. If you want to trap this event and do something it looks like the SetConsoleCtrlHandler function is the way to do it.

See also:

我是男神闪亮亮 2024-07-22 19:13:03

在 Linux 和其他 Unix 系统上,控制台作为单独的进程运行。 当您关闭 shell 时,它会向当前活动的进程或不在后台执行的进程发送 SIGHUP 信号。 如果程序员不处理它,进程就会终止。 如果您关闭与终端和活动进程的 SSH 会话,也会发送相同的信号。

On Linux and other Unix systems, the console runs as a separate process. As you close the shell, it sends the SIGHUP signal to the currently active process or processes that are not executed in the background. If the programmer does not handle it, the process simply terminates. The same signal is sent if you close the SSH session with a terminal and an active process.

相权↑美人 2024-07-22 19:13:03

SIGBREAK 在 Windows 上引发。

SIGBREAK is raised on Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文