I thought that this will run until I sent a signal from my keyboard!
The code is from another person and he said that he tested on a mac.
I run it in Linux, because I think this can't be done from my windows 7.
As you can see I have commented fflush(stdout), but uncommeting it has no effect.
The code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void handlerC(int sig)
{
printf("Crtl-C pressed\n");
printf("Received signal nr %i.\n",sig);
psignal(sig,"handler");
}
void handlerQ(int sig)
{
printf("Received signal nr %i.\n",sig);
psignal(sig,"handler");
printf("bb\n");
exit(1);
}
void waitforever()
{
signal(SIGINT,handlerC); // Ctrl-C
signal(SIGQUIT,handlerQ); //ctrl-\
while(1)
{
putchar('.');
//fflush(stdout);
sleep(2);
}
}
int main(int argc, char* argv[])
{
waitforever();
return 0; // will never be called
}
Output
Code:
linux05:/home/users/std10093>./px
.linux05:/home/users/std10093>
So, only one dot is being printed and then the loop exits and we stop. Why? :/