#SIGINT Ignore

4 messages · Page 1 of 1 (latest)

silver light
#
    void signal_int_handler(int signum) {
        is_foreground ? kill_foreground_prcss() : signal(SIGINT, SIG_IGN);
    }

...

        struct sigaction sig_action;

        sig_action.sa_flags = SA_RESTART;
        sigemptyset(&sig_action.sa_mask); 
        sig_action.sa_handler = sig_child_handler;
        manage_sig_action(&sig_action);

        sig_action.sa_handler = signal_stop_handler;
        sigaction(SIGTSTP, &sig_action, NULL);

        sig_action.sa_handler = signal_quit_handler;
        sigaction(SIGQUIT, &sig_action,NULL);

        sig_action.sa_handler = signal_int_handler; 
        sigaction(SIGINT, &sig_action, NULL);

        return sig_action;

Im trying to ignore ctrl+c if the process is not in the foreground but this is not working, would anyone be able to point me to why?

glass spadeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

frozen vine
#

is_foreground ? kill_foreground_prcss() : signal(SIGINT, SIG_IGN); seems weird. changing the disposition of a signal inside a signal handler (and with signal which is recommended to be avoided) isn't gonna do you any good.
for start it just changes the disposition.
second - it'll change it for successive signals.

you probably want something like this instead:

    void signal_int_handler(int signum) {
        (void)signum;
        if(is_foreground) kill_foreground_prcss();
    }```
and let background process 'fallthrough'