#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#define BUFLEN 255 #define ERR_EXIT(m) \
do \
{ \
perror(m); \
exit(EXIT_FAILURE); \
} while(0) int main(){
int fd;
int fd_log;
char *buf01="open /dev/urandom success\n";
char *buf02="open /dev/urandom failed\n";
char dest[100];
int size;
int max=604800;//7days
int i=0;
time_t timep;
char tmpBuf[BUFLEN]; umask(0);
fd_log = open("/var/log/test_urandom.log",O_CREAT|O_APPEND|O_RDWR,0666);
if (fd_log == -1){
ERR_EXIT("open error");
}else{
printf("open /var/log/test_urandom.log success");
} while(i < max){
fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY); //now
time(&timep);
strcpy(tmpBuf,ctime(&timep)); //failed
if (fd < 0){
strcpy(dest,tmpBuf);
strcat(dest,":");
strcat(dest,buf02);
if((size=write(fd_log,dest,strlen(dest))) < 0){
perror("write failed");
}
}else{ //success
strcpy(dest,tmpBuf);
strcat(dest,":");
strcat(dest,buf01);
if ((size=write(fd_log,dest,strlen(dest))) < 0){
perror("write failed");
}
}
close(fd);
sleep(1);
i+=1;
}
close(fd_log); return 0;
}

C IO programming test code的更多相关文章

  1. [IoLanguage]Io Programming Guide[转]

    Io Programming Guide     Introduction Perspective Getting Started Downloading Installing Binaries Ru ...

  2. hackr.io & Programming Courses & Programming Tutorials

    hackr.io & Programming Courses & Programming Tutorials the Best Programming Courses & Tu ...

  3. Fork and Join: Java Can Excel at Painless Parallel Programming Too!---转

    原文地址:http://www.oracle.com/technetwork/articles/java/fork-join-422606.html Multicore processors are ...

  4. 大家是怎么做Code Review的?

    先说说我们公司现在的做法,一个团队被人为地分为两个阵营:Senior Developers和Junior Developers,比例差不多是1:1,Senior Developers就担负着对Juni ...

  5. net programming guid

    Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...

  6. Important Programming Concepts (Even on Embedded Systems) Part V: State Machines

    Earlier articles in this series: Part I: Idempotence Part II: Immutability Part III: Volatility Part ...

  7. 如何在Etherscan.io 部署ETH以太坊智能合约 如何在15分钟内创建你的加密货币

    一.概述 ETH 网络这里就不介绍了,这篇文章主要记录在以太坊主网和测试网络部署一个智能合约,也就是如何发币. 二.部署合约需要的生产工具      准备工具前,建议大家准备个VPN,因为会访问国外网 ...

  8. 如何用Git.io来生成自定义后缀名的短网址

    如何用Git.io来生成自定义后缀名的短网址 git.io是Github的官方短网址,它是用来缩短Github上项目的网址. 效果:Git.io/wacsh将会跳转到https://xhemj.git ...

  9. .net Framework Class Library(FCL)

    from:http://msdn.microsoft.com/en-us/library/ms229335.aspx 我们平时在VS.net里引用的那些类库就是从这里来的 The .NET Frame ...

随机推荐

  1. 四种ASP网页跳转代码

    时间:2012-06-12 21:12来源:未知 输入:铜都风尘 点击: 32987 次 如果你要在服务器端跳转,可以这样: Response.Redirect(http://blog.163.com ...

  2. linux采用scp命令拷贝文件到本地,拷贝本地文件到远程服务器

    // 假设远程服务器IP地址为 192.168.1.100 1.从服务器复制文件到本地: scp root@192.168.1.100:/data/test.txt /home/myfile/ roo ...

  3. web前端对文件的引用规则

    web前端一般常用文件 .html .css .js.但是当用css文件和html引入资源(比如图片)时,路径可能不相同.下面总结了几条. 使用相对路径引入规则: html或者js引入图片,按照htm ...

  4. CentOS 安装 VMTools

    1.点击虚拟机,选择 安装 VMware Tools 2.把 压缩包 复制到桌面 3.给当前用户管理员权限,然后解压该压缩包 4.进入到解压后的文件夹 5.执行 vmware-install.pl 6 ...

  5. CodeForcesGym 100676G Training Camp

    G. Training Camp Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...

  6. kfka学习笔记一:使用Python操作Kafka

    1.准备工作 使用python操作kafka目前比较常用的库是kafka-python库,但是在安装这个库的时候需要依赖setuptools库和six库,下面就要分别来下载这几个库 https://p ...

  7. ASP.NET - 单元测试

    Assert类的使用 Assert.Inconclusive() 表示一个未验证的测试: Assert.AreEqual() 测试指定的值是否相等,如果相等,则测试通过: AreSame() 用于验证 ...

  8. [Linux]第四部分-Linux用户管理

    登陆过程:1.从etc/passwd中查找账号,没有则退出,然后在etc/shadow中读出uid与密码表passwd中内容格式 用户名:密码:UID:GID:用户信息说明:家目录:用户所用Shell ...

  9. redis代码解析-事务

    redis 的事务相关的几个命令分别为 watch multi exec. watch 可以监控一个变量在事务开始执行之前是否有被修改.使用方式为: WATCH key [key ...] 在redi ...

  10. [ES6] Proxy & Reflect

    Proxy and Reflect API works nicely together. About how to use Proxy, check this post. Let's see abou ...