<>信号量

 

定时器alarm

/* alarm_pause.c */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
 /*调用alarm定时器函数*/
 int ret = alarm(5);
 pause();
 printf("I have been waken up. ret=%d\n",ret); /* 此语句不会被执行 */
 return 0;
}

结果:

lsb@ubuntu:~/gx/wangluo$ ./alarm_pause

停5秒后
Alarm clock

****************************************************************************

/* alarm_pause.c */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

static void sig_alrm(int signo)
{
    printf("Receive Alarm signal\n");
}
int main()
{
 if (signal(SIGALRM, sig_alrm) == SIG_ERR)
         return -1;
 /*调用alarm定时器函数*/
 int ret = alarm(5);
 pause();
 printf("I have been waken up. ret=%d\n",ret); /* 此语句会被执行 */
 return 0;
}
结果:

lsb@ubuntu:~/gx/wangluo$ ./alarm_pause_ok

停5秒后
Receive Alarm signal
I have been waken up. ret=0
*********************************************************************

********************************************************************

你可能感兴趣的:(ubuntu,Signal)