0

In my main.c file i have the code below. Everything works fine but when i create a signal by using ctrl+c; execution pauses at sleep(1), intHandler function works, then program gives segmentation fault in sleep(1) line.

Any one has any idea what should cause this? I cant execute the last two lines in RunMe() and because of this i cant close my open sockets and threads properly.

volatile sig_atomic_t keepRunning = 1;


void intHandler(int exitCode)
{

    keepRunning = 0;
}

int RunMe()
{
    // some unrelated code runs in here
    // preperation of sockets and threads etc.

    while (keepRunning == 1)
    {
        printf("KR:%d\n",keepRunning);
        sleep(1); // here produces the segmentation fault.
        if (iLogger.stateRequested == ITRUE)
        {
            printState(&fp);
            iLogger.stateRequested = IFALSE;
        }

    }
    // both two below closes my sockets and threads
    iLogger.Destroy();
    fp.RemoveAll(&fp);
}


int main(int argc, char *argv [])
{ 
    signal(SIGINT, intHandler);
    RunMe();
}
obayhan
  • 1,636
  • 18
  • 35
  • I tried the program, but have remove all ilogger calls, but this shouldn't change anything, and the program ran fine. I am using manjaro linux. – Alexander Daum Apr 17 '17 at 08:48
  • possible duplicate of http://stackoverflow.com/questions/36215399/why-can-interrupt-handler-has-sleep-functionality – Marian Apr 17 '17 at 09:01
  • Maybe background threads may cause this then? – obayhan Apr 17 '17 at 09:01
  • @Marian no. Even if you remove sleep in interrupt handler i got same result. Here i re arranged the code. – obayhan Apr 17 '17 at 09:03

0 Answers0