12.5 beep 以及 系统中的延时函数

来源:互联网 发布:amc分析知乎 编辑:程序博客网 时间:2024/06/11 15:47
应用层:
1.系统中的延时函数  头文件 #include <unistd.h>
    sleep(2)  
    功能:延时2 妙
    usleep()
    功能:延时微妙
2.#include _POSIC_C_SOURCE  199309
    #include <time.h>
    int  nanosleep(const struct timespec *req , struct timespec *rem)

    struct timespec{
        time_t tv_sec; //seconds 秒
        long tv_nsec; //nanoseconds 纳秒  范围[0 , 99999 9999]
    }
    功能:暂停某个线程 ,直到你规定的时间到后恢复状态;使其进入 TASK_INTERRUPTIBLE 状态;时间到 或者 被信号打断,进程 恢复为 TASK_RUNING 状态;若是被信号唤醒的 此时返回 -1,如果 定义的 rem 不为空,则剩余的时间存入 rem;

内核层:
1.#include <linux/delay.h>
     ndelay( )  //纳秒
     udelay( )  //微妙
    mdelay( ) // 毫秒

//**************************************************************************************************
系统中的响铃 分析

#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <curses.h>

/*int main()
{
int i = 0;
for(i = 0; i < 10; i ++)
{
sleep(1);
fprintf(stdout,"\7");
fflush(stdout);     //这里 不加 fflush 只会在最后循环完的 时候 响一次铃
}
return 0;
}
*/

int main()   //这个不知道为什么不会响铃   在头文件中 包含了 include <curses.h>  编译:cc  *.c  -lcurses
{
while(1)
{
sleep(1);
printf("hao hao hao>>>>>>>>>>>>\n");
beep();
printf("hao are you....!");
}
}