1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <string> #include <execinfo.h> #include <thread> #include <signal.h>
using namespace std;
bool flag = true;
void () { while (flag) { cout << 1 << endl; this_thread::sleep_for(chrono::seconds(1)); } }
void SignalHandler(int sig) { signal(sig, SIG_DFL);
const int maxFrames = 100; void* frames[maxFrames]; string result; int numFrames = backtrace(frames, maxFrames); char** symbols = backtrace_symbols(frames, numFrames); for (int i = 0; i < numFrames; i++) { cout << frames[i] << ":" << symbols[i] << endl; }
flag = false; }
void RegistSignalHandler() { signal(SIGINT, SignalHandler); }
int main() { cout << "开始" << endl;
RegistSignalHandler();
thread td(&test);
td.join();
cout << "结束" << endl;
return 0; }
|
近期评论