Cygwin CTRL-C(信号中断)无法正常工作 - JVM Shutdown Hooks无法启动 [英] Cygwin CTRL-C (Signal Interrupts) not working properly - JVM Shutdown Hooks not starting

查看:366
本文介绍了Cygwin CTRL-C(信号中断)无法正常工作 - JVM Shutdown Hooks无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个利用关闭挂钩的Java应用程序,以便清除程序的终止/中断,但我注意到Cygwin的CTRL-C实现似乎没有触发关闭挂钩。从表面上看,它似乎已经中断了进程,将控制权放回命令行,但是根本没有触发进程'关闭挂钩,因此不会发生清理。

I'm working on a Java application that utilises shutdown hooks in order to clean up on termination/interruption of the program, but I've noticed that Cygwin's implementation of CTRL-C doesn't seem to trigger the shutdown hooks. On the surface it appears to have interrupted the process, relinquishing control back to the command line, however the process' shutdown hooks are not triggered at all so cleanup does not occur.

在cmd中它们被捕获,但由于各种约束,我需要以某种方式让它们在Cygwin中工作。

In cmd they get caught, but due to various constraints I need to somehow get them working in Cygwin.

有没有办法在正在运行的进程中触发SIGINT Cygwin,或者可能是关闭钩子的替代品,我可以用来清理中断和终止?

Is there any way to fire a SIGINT at a running process through Cygwin at all, or perhaps an alternative to shutdown hooks that I could use to clean up on interruption and termination?

推荐答案

Bash调用非cygwin(windows)可执行文件通过中间bash进程(bash shell - > bash - > java)。键入Ctrl-C时,bash进程获取SIGINT并终止子进程,因此不会调用shutdown挂钩。 Windows进程不知道SIGINT,SIGTERM或SIGKILL等信号。

Bash invokes non-cygwin (windows) executables through an intermediate bash process (bash shell -> bash -> java). When you type Ctrl-C, the bash process gets a SIGINT and kills the child java process, so the shutdown hooks are not invoked. Windows processes are not aware of signals like SIGINT, SIGTERM or SIGKILL.

- Xrs 选项文档,java进程注册CTRL_C_EVENT窗口事件的控制台控制处理程序,并触发调用的正常终止关机钩子。为了让Ctrl-C按预期工作,你需要确保java进程收到它,但是现在它被bash拦截而没有传递给子进程。

As described in the -Xrs option documentation, the java process registers a console control handler for the CTRL_C_EVENT windows event and that triggers a graceful termination that invokes the shutdown hooks. To get Ctrl-C to work as expected, you'd need to make sure the java process receives it, but right now that's intercepted by bash and not passed forward to the child process.

此问题可以重写为:如何让Cygwin将Ctrl-C转发到Windows控制台进程?

This issue can be restated as: How can I have Cygwin pass Ctrl-C forward to windows console processes?

注意:上述bash行为已经过验证版本1.7.25。

Note: The bash behavior described above was verified on version 1.7.25.

这篇关于Cygwin CTRL-C(信号中断)无法正常工作 - JVM Shutdown Hooks无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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