@@ -2122,7 +2122,11 @@ static void append_to_generated_text_from_generated_token_probs(llama_server_con
21222122}
21232123
21242124std::function<void (int )> shutdown_handler;
2125- inline void signal_handler (int signal) { shutdown_handler (signal); }
2125+
2126+ inline void signal_handler (int signal) {
2127+ exit (1 );
2128+ }
2129+
21262130
21272131// ///////////////////////////////
21282132// //////////////////////////////
@@ -2649,6 +2653,20 @@ void RunServer(const std::string& server_address) {
26492653int main (int argc, char ** argv) {
26502654 std::string server_address (" localhost:50051" );
26512655
2656+ #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
2657+ struct sigaction sigint_action;
2658+ sigint_action.sa_handler = signal_handler;
2659+ sigemptyset (&sigint_action.sa_mask );
2660+ sigint_action.sa_flags = 0 ;
2661+ sigaction (SIGINT, &sigint_action, NULL );
2662+ sigaction (SIGTERM, &sigint_action, NULL );
2663+ #elif defined (_WIN32)
2664+ auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
2665+ return (ctrl_type == CTRL_C_EVENT) ? (signal_handler (SIGINT), true ) : false ;
2666+ };
2667+ SetConsoleCtrlHandler (reinterpret_cast <PHANDLER_ROUTINE>(console_ctrl_handler), true );
2668+ #endif
2669+
26522670 // Define long and short options
26532671 struct option long_options[] = {
26542672 {" addr" , required_argument, nullptr , ' a' },
0 commit comments