I have an executable loop.exe
on my Windows machine that was compiled using MinGW's gcc.
The code for loop.c
is behaviorally similar to:
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
static int sigintReceived = 0;
void sigint_handler(int signum){
sigintReceived = 1;
}
int main(){
signal(SIGINT, sigint_handler);
while(1){
sleep(1);
if(sigintReceived){
printf("SIGINT received");
exit(0);
}
}
}
If I open a Cygwin terminal using Cygwin.bat
and run ./loop.exe
and then press Ctrl+C I will see the output:
SIGINT received
However if I open two terminals using Cygwin.bat
and run ./loop.exe
in one and kill -2 <LOOP_EXE_PID>
in the other, I do not see the output at all.
The code is acting as if no signal handler exists when I run kill -## <LOOP_EXE_PID>
with any signal and handler (for example if I kill -10
I'll get a Bus error
or if I kill -12
I'll get a Bad system call
or if I kill -11
I'll get a Segmentation fault
)
I have looked around and come across this answer which I believe might relate to what I'm encountering, however loop.exe
is being terminated in each case. In this answer Bogdan mentions that Windows executables are not run directly by the Bash shell but rather through an intermediate Bash process, and I can see this process in my Windows Task Manager when I run ./loop.exe
, but I cannot see this intermediate Bash process from inside Cygwin.
Any ideas as to how I can get kill -2 <LOOP_EXE_PID>
to act the same as Ctrl+C? Or, any ideas how I can see this intermediate Bash process from inside Cygwin?
Note: I am running Cygwin using C:\cygwin\Cygwin.bat
; I am not using mintty.