New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CTRL-C doesn't interrupt the running process #684
Comments
Really any program? Try sleep 99, Ctrl+C, check with ps - no more sleep. |
Thanks for your response. I have investigated a bit further and it seems that There is still an issue here, however. When I Ctrl-C, the running program gets killed rather than interrupted. This prevents applications from cleaning up properly and leads to leaking the processes. You can try reproduce with this Go gist. When I run this in ConEmu, PowerShell, cmd, everything is handled as expected:
But, when I run this via GitBash or Cygwin, the interrupt signal is not passed correctly to the program:
Also, this wouldn't be end of the world if the whole process tree was killed properly. Unfortunately, seems like the child processes are not killed. (BTW, |
Obviously int_test.exe is not a Cygwin program. |
@k-takata thanks for pointing me in the right direction. That's right, when I run this with What is strange is that we did not experience the issue with the whole process tree not being killed with mintty 2.6.2 (git-for-windows 2.10.2). We only started to experience problems when using mintty 2.7.7 (git-for-windows 2.14.1). |
Cannot reproduce any processes other than it itself to appear at all, so I cannot check either whether they are killed. Without further evidence, I can only close the issue. |
You could make a wrapper for invocation of course. |
Any news here, i'm facing the exact same issue. We didn't have that problem with pre git-for-windows 2.14.1 versions as well. Problem appeared in 2.14.1 and even reinstalling old didn't change it. |
Ok, the pointer, that maybe cygwin is the problem here, leaded me to search for cygwin files. Turned out that there are some cygwin related files in git folder - which are not getting deleted on uninstalled. So these files might have the problem - not sure if this is git-for-windows related or mintty. Then i did manually clean git folder and reinstalled Git-2.10.2-64-bit and voila no issues. |
This sounds mysterious, but glad it's solved for you. |
Same issue? gradle? int_test.exe? |
Having a slightly different issue with Ctrl-C. When a mintty terminal is started like this: On the other hand, if a shell is started by running Version:
|
Why do you think it's mintty-related? Mintty only forwards the Ctrl-C to the pty (the cygwin-managed communication interface), which then may generates an interrupt (or not, as configured) to the application, which may then ignore or catch the interrupt (as configured). If the only difference is |
I tried executing the program by starting a shell in one of the following four ways:
The test program is a very simple .NET console app listed below. Correct "Ctrl-C" behavior: "Setting abort flag" is printed, and the program is exited gracefully. Incorrect behavior - nothing is printed, the process is killed: namespace Test {
class Program {
static bool Abort { get; set; }
static void Main(string[] args)
Console.CancelKeyPress += (c, ev) => {
Console.WriteLine("Setting abort flag");
ev.Cancel = true;
Abort = true;
};
var end = DateTime.Now.AddSeconds(60);
while(!Abort && DateTime.Now < end)
Thread.Sleep(1000);
}
}
} Or a similar test in C++: #include "stdafx.h"
#include <windows.h>
#include <stdio.h>
BOOL CtrlHandler( DWORD code )
{
switch( code )
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
printf( "Ctrl-C event\n\n" );
return true;
// CTRL-CLOSE: confirm that the user wants to exit.
case CTRL_CLOSE_EVENT:
printf( "Ctrl-CLOSE event\n\n" );
return true;
// Pass other signals to the next handler.
case CTRL_BREAK_EVENT:
printf( "Ctrl-BREAK event\n\n" );
return false;
case CTRL_LOGOFF_EVENT:
printf( "Ctrl-LOGOFF event\n\n" );
return false;
case CTRL_SHUTDOWN_EVENT:
printf( "Ctrl-SHUTDOWN event\n\n" );
return false;
default:
return false;
}
}
int main()
{
if(!SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE)) {
printf( "ERROR: Could not set control handler: %d", GetLastError());
return 1;
}
printf( "\nThe Control Handler is installed.\n" );
printf( " -- Now try pressing Ctrl+C or Ctrl+Break, or\n" );
printf( " try logging off or closing the console...\n\n" );
while (true)
Sleep(1000);
} |
So it's not a cygwin program (which you didn't mention before). |
Thank you for clarifying |
I have the same issue running maven. If I execute and then try to stop the process with CTRL+C, it does not work. It terminates fine in CMD and WSL ubuntu bash. Is there any specific trick needed to get this working? |
winpty |
Actually it does not work: miha@DESKTOP-CEC4TIT MINGW64 ~/Desktop miha@DESKTOP-CEC4TIT MINGW64 ~/Desktop So maven quite obviously is installed, and cannot be interrupted without winpty, and does not work with winpty. Any other possible solution? |
I'm on Windows 10 and when doing a git diff after it's completed I hit CTRL+C then the process ends and when I get to prompt I can't see any characters that I type, but when I hit return it shows what I typed even though I can't see the characters. So if I type dddksdjfl I can't see it but when I hit enter I see - bash: dddksdjfl: command not found. This is new the last couple of releases. Any way to show the characters again? Should I try not using mintty in setup of Git? Have to keep starting new windows to get any work done :( (newbie) Thanks! |
What do the following commands respond: |
|
|
< < |
I was asking $TERM, not $term. |
erg. sorry. newbie... :( < |
First diagnostics give not immediate hint, I'll check tomorrow. |
Yeah, I just found q. Still a strange result. Thanks! |
I am running cygwin 2.10.0(0.325/5/3)
When I do Ctrl + c, the process is still running When I run storybook on a normal Command Prompt, Ctrl + c kills the process as expected. |
netstat is not a cygwin program. Signal handling of native Windows program and cygwi does not interoperate well. For a workaround, see comments above about winpty. |
which npm produces this:
How can I tell if this is a cygwin program or not? The issue I am facing is that when I start an app with
The site is hosted, say, at http://localhost:3000 When I do CTRL-C, and then npm start again, it would complain the port is still in use.
I am trying to use winpty, but what is the correct syntax? |
If a command is a batch file (
Normally cygwin programs are installed in /bin, /usr/bin or /usr/local/bin. |
@k-takata Thanks for the tip on adding .cmd. This is working for me:
|
Putting this in .bashrc / .zshrc might help: alias npm="winpty -- /cygdrive/c/Program\ Files/nodejs/npm.cmd" Adjust to the location of your npm installation accordingly. |
I have this problem with Symfony Console commands; they cannot be aborted with CTRL+C. I don't believe this ever used to happen on Windows 7, though, only since upgrading to Windows 10. |
From the point of view of the terminal, Ctrl+C is a plain normal character, nothing special. |
In the meantime, there is still the |
Do you know when the next Cygwin release might be? |
You can try test release 3.1.0 already. |
you have to specify the extension of the file you run with the comment, refer to my comment here: It's funny because git-for-windows has no problem terminating the processes with ctrl-c, no idea if this is a mitty or cygwin issue. I'm using Msys2. |
No, you don't. You do, however, have to specify a real binary. It does not work with shebang lines. |
oh well I can't tell what your |
Problem persists in mintty 3.5.0 with programs such as maven. Using mintty bundled with latest msys2. |
Interestingly enough, same operations on mintty bundled with git for windows work as they should. I suppose their fork handles some things in a different way? |
MSYS2 and Git for Windows disable "ConPTY" support by default. Actually ConPTY is supposed to improve such interworking problems, not make them worse. Please report this to the cygwin mailing list, it's not a terminal issue. |
When I run any program that will take a bit longer to complete and CTRL-C interrupt it while it runs, the console will release and go back to the command prompt, however the program continues to run and print asynchronously to the console window.
For example:
This is the case for any program, not just
gradle
. I've seen this with Cygwin and GitBash - seems they have themintty
in common, while this doesn't happen with ConEmu.This only started since I have updated from git-for-windows (GitBash)
2.10.2
to2.14.1
.The text was updated successfully, but these errors were encountered: