Last active
May 10, 2024 13:52
-
-
Save rdp/f51fb274d69c5c31b6be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// attribution: http://stackoverflow.com/a/15281070/32453 | |
// you can compile this with gcc [mingw or mingw-w64] and probably other compilers as well | |
#include <stdlib.h> // NULL | |
#include <stdbool.h> // false | |
#include <windows.h> // AttachConsole, CTRL_C_EVENT, etc. | |
#include <stdio.h> // printf | |
#include <strsafe.h> | |
void logLastError() | |
{ | |
LPTSTR errorText = NULL; | |
FormatMessage( | |
// use system message tables to retrieve error text | |
FORMAT_MESSAGE_FROM_SYSTEM | |
// allocate buffer on local heap for error text | |
|FORMAT_MESSAGE_ALLOCATE_BUFFER | |
// Important! will fail otherwise, since we're not | |
// (and CANNOT) pass insertion parameters | |
|FORMAT_MESSAGE_IGNORE_INSERTS, | |
NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM | |
GetLastError(), | |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
(LPTSTR)&errorText, // output | |
0, // minimum size for output buffer | |
NULL); // arguments - see note | |
if ( NULL != errorText ) | |
{ | |
printf("failure: %s", errorText); | |
LocalFree(errorText); | |
errorText = NULL; | |
} | |
} | |
void sendCtrlC(int pid) | |
{ | |
//This does not require the console window to be visible. | |
printf("sending ctrl+c to pid %d", pid); // if we want to log anything at all, have to log here or we'll be sending it to the other console with printf [!] XXX could maybe duplicate descriptors first or some odd...oh well. | |
FreeConsole(); // free ourselves from our current console, in case we're being run from a cmd.exe otherwise can't attach to another (at most one). And we probably are...if it fails because we don't have one, that's OK too. | |
if (AttachConsole(pid)) | |
{ | |
// Disable Ctrl-C handling for our own program, so we don't "kill" ourselves on accident...though that might not hurt currently... | |
SetConsoleCtrlHandler(NULL, true); | |
GenerateConsoleCtrlEvent(CTRL_C_EVENT , 0); // these get sent to every process attached to this console, FWIW... | |
// TODO could wait here for process to exit, hard kill it after a sufficient wait, etc. see http://stackoverflow.com/a/31020562/32453 | |
// could also send it *another* ctrl_c_event, for instance if you're trying to interrupt something in a batch file and it has that ugly "Batch file interrupted, continue [y/n]" [?] | |
} | |
else { | |
logLastError(); // failure, PID might no longer exist, show a GUI error window | |
} | |
} | |
int main( int argc, const char* argv[] ) { | |
// assume they know the pid... | |
if (argc != 2) { | |
printf("syntax: pid"); | |
return 1; | |
} | |
int pid = atoi(argv[1]); | |
sendCtrlC(pid); | |
} |
Can be your solution working in those files?
https://github.com/ibc/mediasoup/blob/master/worker/src/Loop.cpp
https://github.com/ibc/mediasoup/blob/master/worker/src/main.cpp
There are linux 's pthread_sigmask family, just wondering if that equivalent for window's setctrlC(pid)
doesn't compile with mingw x64
You could try it from the exe...
…On Tuesday, June 13, 2023, jredfox ***@***.***> wrote:
@jredfox commented on this gist.
________________________________
doesn't compile with mingw x64
—
Reply to this email directly, view it on GitHub or unsubscribe.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS or Android.
This was originally for visual studio, some modification will be needed for
mingw...
…On Tue, Jun 13, 2023 at 11:10 PM jredfox ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
I need the actual imports. I tried them with mingw and it’s not working.
Perhaps it’s not linking the kernal32 or something provide exact steps for
eclipse to resolve the linking error. My compiler is the recommended from
sourceforge 2014 which is 14 years after the minimum that function was in
there
From: Roger ***@***.***>
Sent: Tuesday, June 13, 2023 11:32 PM
To: ***@***.***>
Cc: ***@***.***>
Subject: Re: rdp/send_ctrl_c.c
@rdp commented on this gist.
You could try it from the exe...
On Tuesday, June 13, 2023, jredfox ***@***.***> wrote:
> @jredfox commented on this gist.
> ________________________________
>
> doesn't compile with mingw x64
>
> —
> Reply to this email directly, view it on GitHub or unsubscribe.
> You are receiving this email because you authored the thread.
>
> Triage notifications on the go with GitHub Mobile for iOS or Android.
>
>
—
Reply to this email directly, view it on GitHub<
https://gist.github.com/rdp/f51fb274d69c5c31b6be#gistcomment-4598883> or
unsubscribe<
https://github.com/notifications/unsubscribe-auth/ACKJBMN6Q4AHQL74F4Z4VY3XLE5G5BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDGNRVGU4DENNHORZGSZ3HMVZKMY3SMVQXIZI
>.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS<
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android<
https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
>.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/rdp/f51fb274d69c5c31b6be#gistcomment-4598895> or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADBUDDIBRYH7BF3JMX363XLFBVVBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDGNRVGU4DENNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
https://github.com/jredfox/WINSIG fixes it and is a lot more simpler then yours. You execute it off as a separate process so it doesn’t screw up your own. NOTE: this is copyrighted as it’s part of a bigger library and will be sold to another company. But since it’s 4 lines of code you can just edit the last line and rename the lib for your own. The last line you can check SIGINT/CONTROL+C instead of if it’s a control+break.
From: Roger ***@***.***>
Sent: Monday, June 19, 2023 7:11 PM
To: ***@***.***>
Cc: ***@***.***>
Subject: Re: rdp/send_ctrl_c.c
@rdp commented on this gist.
This was originally for visual studio, some modification will be needed for
mingw...
On Tue, Jun 13, 2023 at 11:10 PM jredfox ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
I need the actual imports. I tried them with mingw and it’s not working.
Perhaps it’s not linking the kernal32 or something provide exact steps for
eclipse to resolve the linking error. My compiler is the recommended from
sourceforge 2014 which is 14 years after the minimum that function was in
there
From: Roger ***@***.***>
Sent: Tuesday, June 13, 2023 11:32 PM
To: ***@***.***>
Cc: ***@***.***>
Subject: Re: rdp/send_ctrl_c.c
@rdp commented on this gist.
You could try it from the exe...
On Tuesday, June 13, 2023, jredfox ***@***.***> wrote:
> @jredfox commented on this gist.
> ________________________________
>
> doesn't compile with mingw x64
>
> —
> Reply to this email directly, view it on GitHub or unsubscribe.
> You are receiving this email because you authored the thread.
>
> Triage notifications on the go with GitHub Mobile for iOS or Android.
>
>
—
Reply to this email directly, view it on GitHub<
https://gist.github.com/rdp/f51fb274d69c5c31b6be#gistcomment-4598883> or
unsubscribe<
https://github.com/notifications/unsubscribe-auth/ACKJBMN6Q4AHQL74F4Z4VY3XLE5G5BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDGNRVGU4DENNHORZGSZ3HMVZKMY3SMVQXIZI
>.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS<
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android<
https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
>.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/rdp/f51fb274d69c5c31b6be#gistcomment-4598895> or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADBUDDIBRYH7BF3JMX363XLFBVVBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDGNRVGU4DENNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
—
Reply to this email directly, view it on GitHub<https://gist.github.com/rdp/f51fb274d69c5c31b6be#gistcomment-4604370> or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACKJBMOMVYR7G4WG5LZRAB3XMDTDZBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDGNRVGU4DENNHORZGSZ3HMVZKMY3SMVQXIZI>.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
compiling OK here (with a bunch of warnings) using gcc.exe ... glad you found something, peace!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
binary version downloadable here: https://sourceforge.net/projects/mplayer-edl/files/send_ctrl_c.exe/download