Ctrl+C kills the process abruptly #22388

Open
opened 2026-01-31 08:11:42 +00:00 by claunia · 0 comments
Owner

Originally created by @rom1v on GitHub (Oct 12, 2024).

Windows Terminal version

No response

Windows build number

No response

Other Software

No response

Steps to reproduce

Hello,

In a program called scrcpy that I develop, I listen to Ctrl+C on Windows using SetConsoleCtrlHandler(windows_ctrl_handler, TRUE);:

665ccb32f5/app/src/scrcpy.c (L148-L149)

It works correctly in the default (old) Windows console (typically started by cmd.exe), Ctrl+C is catched and the program can terminate gracefully (finishing writing a video footer for example).

However, from Windows Terminal, it has been reported that Ctrl+C terminates the process abruptly (which in that case cause the recorded mp4 file to be corrupted, but any other cleanup actions cannot be executed): https://github.com/Genymobile/scrcpy/issues/5122#issuecomment-2243087702

Is there a reason for this behavior?

Thank you for your help.

Expected Behavior

The Ctrl handler should be executed on Ctrl+C.

Actual Behavior

The process is killed abruptly on Ctrl+C.

Originally created by @rom1v on GitHub (Oct 12, 2024). ### Windows Terminal version _No response_ ### Windows build number _No response_ ### Other Software _No response_ ### Steps to reproduce Hello, In a program called scrcpy that I develop, I listen to Ctrl+C on Windows using `SetConsoleCtrlHandler(windows_ctrl_handler, TRUE);`: https://github.com/Genymobile/scrcpy/blob/665ccb32f5306ebd866dc0d99f4d08ed2aeb91c3/app/src/scrcpy.c#L148-L149 It works correctly in the default (old) Windows console (typically started by `cmd.exe`), Ctrl+C is catched and the program can terminate gracefully (finishing writing a video footer for example). However, from Windows Terminal, it has been reported that Ctrl+C terminates the process abruptly (which in that case cause the recorded mp4 file to be corrupted, but any other cleanup actions cannot be executed): https://github.com/Genymobile/scrcpy/issues/5122#issuecomment-2243087702 Is there a reason for this behavior? Thank you for your help. ### Expected Behavior The Ctrl handler should be executed on Ctrl+C. ### Actual Behavior The process is killed abruptly on Ctrl+C.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22388