23,116
社区成员
发帖
与我相关
我的任务
分享
/** Author : kotrue
* Tm&Add : 22:54:00 10/16/2011 in USTB
* Notes : non-reentrant functions.
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <bits/signum.h>
void signal_handler(int signum);
// use static data structure.
static char str[20];
int main()
{
strcpy(str, "\n");
signal(SIGALRM, signal_handler);
alarm(1);
while(1)
{
printf("%s", str);
strcpy(str, "hello world\n");
strcpy(str, "WWWWWWWWWWW\n");
alarm(1);
}
return 0;
}
void signal_handler(int signum)
{
printf("%s", str);
alarm(1);
}