#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. LCA-倍增法(写给自己看)

    LCA-倍增法 题目又做不下去来写题解了 算法思想 类似于ST表的思想维护dp[i][j]:节点i向上跳2^j高度的的节点 转移方程 \(dp[i][j]=dp[dp[i][j-1]][j-1]\)注 ...

  2. html页面之间传值问题

    1.如再A页面(A.html)通过window.open(B.html?code=11)或者通过其他方式跳转到其它html页面时: 可通过以下方式进行传递参数. //B.html页面function ...

  3. html中的meta标签属性

    <!-- 声明文档使用的字符编码 --> <meta charset='utf-8'> <!-- 优先使用 IE 最新版本和 Chrome --> <meta ...

  4. HDU 5322 Hope (分治NTT优化DP)

    题面传送门 题目大意: 假设现在有一个排列,每个数和在它右面第一个比它大的数连一条无向边,会形成很多联通块. 定义一个联通块的权值为:联通块内元素数量的平方. 定义一个排列的权值为:每个联通块的权值之 ...

  5. [luogu3261 JLOI2015] 城池攻占 (左偏树+标记)

    传送门 Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池.这 n 个城池用 1 到 n 的整数表示.除 1 号城池外,城池 i 会受到另一座城池 fi 的 ...

  6. django模板使用

    概述 模板由两部分组成,HTML代码,逻辑控制代码,作用:快速生成HTML页面,优点:模板的设计实现了业务逻辑与现实内容的分离 定义模板 挖坑与继承 模板继承可以减少页面的内容的重复定义,实现页面的重 ...

  7. 《代码敲不队》第八次团队作业:Alpha冲刺 第三天

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 代码敲不队 作业学习目标 掌握软件编码实现的工程要求. 团队项目github仓库地址链接 GitH ...

  8. PHP面向对象(二)

    7 多态 多态: 多种形态 多态分俩种: 方法重写和方法加载 7.1 方法重写 子类重写了父类的同名的方法 <?php class Person{ public function show(){ ...

  9. 【hiho一下 第三周】KMP算法

    [题目链接]:http://hihocoder.com/problemset/problem/1015 [题意] [题解] 把f数组,len1,len2数组一开始全都定义成char型 这酸爽. [Nu ...

  10. 告诉你 SQL 数据库与 NoSQL 数据库的区别

    简单来说 SQL 数据库和 NoSQL 数据库有着共同的目标:存储数据,但存储的方式不同 一. 表 SQL中的表结构具有严格的数据模式约束: 存储数据很难出错. NoSQL存储数据更加灵活自由:可能导 ...