how to prevent Ctrl+Break/Ctrl+C from closing both programs if one was launched from another by system() or CreateProcess()?
c++, console, windows
Solution
Add this::
#include <signal.h>
...
signal (SIGINT, SIG_IGN);
After the `signal()` call, the program ignores Ctrl-Break. On Linux, ignoring signals propagates to child processes through `fork()`/`exec()`.
I would expect Windows to reset the default signal handling on `exec()` due to the way the O/S + runtime library work. So if you want the child to ignore Break, add the code above to it too.
Problem
This is test example: (1). simple program doing endless loop: ``` #include <iostream> using namespace std; int main() { int counter = 0; while (1) cout << ++counter << ": endless loop..." <<endl; } ``` (2). another program that launches above example through `system()` command: ``` #include <iostream> #include <windows.h> using namespace std; int main() { system("endless_loop.exe"); cout << "back to main program" << endl; } ``` When doing `Ctrl+Break` on this program text `back to main program` doesn't show. How to restrict this key combination to inside process and return execution pointer back to main app ? Another thing is that I don't always have control over source code of inside program, so I can't change things there.