How to handle SIGWINCH signal ?

I’m using ncurses library with qnx core 6.3.2
and I want to catch SIGWINCH signal
(“window change”; if terminal is resized).

My code:

signal( SIGWINCH, my_handler ); // install my_handler

signal( SIGWINCH, SIG_DFL ); // restore default action

void my_handler( int sig_number ) // sig. handler
{
int nh, nw;
getmaxyx(stdscr, nh, nw);
}

My program works well,
but when SIGWINCH signal arrives
program gets killed ! (it is immediately terminated)
Why?

Why do you call signal() a second time with SIG_DFL? You should not, it cancels the effect of the first signal().

Make sure any function you call int the signal handler is signal safe.

I know that - Don’t treat me like c/c++ kid :slight_smile:.

I install my handler & than wait (in loop) for signal to come.
But when the signal arrives - my program is ‘brutally’ terminated !
/and I don’t know why ?..

I have no way to know what you know…

Please define “brutally” terminated, do you get a core dump? What happen if you do nothing inside the handler.

no, there is no message - it is like normal, clean exit, but it isn’t normal;
with empty handler is the same :frowning:

signal( SIGWINCH, my_handler ); // install my_handler

void my_handler( int sig_number ) // sig. handler
{
}

What do you mean by normal, clean exit?

Is it possible you are getting a different signal then SIGWINCH, that you aren’t handling (i’m not familliar with ncurse)

What if you ignore the signal (SIG_IGN) instead.

What if the function that is being interrupted return -1 with errno = EINTR and that it’s not being handled properly.

Run it in gdb and you’ll see the signals that are
hitting it.

-seanb