EmbLogic's Blog

not executing the Signal handler function

Hi All,

in the following program I have observed that the program is not jumped on the handler but if i remove the statement sleep(1); it work fine.

the piece of the code is

while(1)

{

if (flag)

printf(“waiting for signal”);

else

printf(“signal invoked”);

sleep(1);

}

my question is when we press Ctrl+C (generating a signal) in such case the program should moved to signal handler function but in this case why it is not working correctly while having sleep(1); statement there why it is so?

3 Responses to not executing the Signal handler function

  1. pradyot says:

    I too faced this problem.

    It may sound weird but for unknown reasons, adding a newline character ‘\n’ at the end of every call to printf function solves the problem.

    so change your printf calls to include a newline character at the end.
    It works.

  2. m.siddarth says:

    Use comma operator after printf(). i.e.

    printf(“signal invoked”),sleep(1);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>