⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fifo03.c

📁 嵌入式Linux程序设计与应用案例 电子书源码 中国电力出版社
💻 C
字号:
/***********
//  name : fifo03.c
//  author : pyy
//  date : 2007-11-23
***************/

#include<sys/types.h>
#include<sys/stat.h>
#include<errno.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<limits.h>
#include<fcntl.h>
#include<time.h>

int main( void )
{
    int fd;
    int len;
    char buf[PIPE_BUF];
    time_t tp;
    mode_t mode=0666;
    /* 删除 test FIFO*/
    unlink("test");
    /* 建立名为test 的 FIFO*/
    if ((mkfifo("test",mode))<0)
    {
        perror("mkfifo error"); exit(1);	
    }	
    printf("fifo03 运行中.......\n");
    /* 打开名为 test  的 FIFO*/
    fd = open("test",O_WRONLY);
    if (fd< 0) {perror("open error"); exit(1);}
    while(1)
    {
        time(&tp); //取得当前时间
        len = sprintf(buf ,"fifo03 返回的当前时间为 %s" ,ctime(&tp));
        /* 将当前时间写入FIFO */
        if ((write(fd, buf ,len+1))<0) 
        {
            perror("write error");
            close(fd);
            exit(1);	
        }	
        sleep(3);
    }
    close(fd); exit(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -