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();
}