#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. Unicode编码,解释UCS、UTF、BMP、BOM等名词

    (转载 谈谈Unicode编码,简要解释UCS.UTF.BMP.BOM等名词 这是一篇程序员写给程序员的趣味读物.所谓趣味是指可以比较轻松地了解一些原来不清楚的概念,增进知识,类似于打RPG游戏的升级 ...

  2. js操作url参数

    function getQueStr(url, ref) //获取参数值 { var str = url.substr(url.indexOf('?') + 1); if (str.indexOf(' ...

  3. Linux学习一:图解CentOS 6.5安装步骤

    1 进入安装界面 2 选择语言 3 选择键盘 4 选择存储类型 5 是否格式化硬盘 6 设置主机名 7 配置网卡 (1)选择网卡并编辑 (2)配置IPv4 (3)查看虚拟网络编辑器 NAT设置 DHC ...

  4. Python爬虫基础--爬取车模照片

    import urllib from urllib import request, parse from lxml import etree class CarModel: def __init__( ...

  5. [剑指offer] 29. 顺时针打印矩阵 (for循环条件)

    思路: 先定义左上和右下角点坐标,打印可分为从左到右,从上到下,从右到左,从下到上.依次判断最后一圈的四个循环条件. #include "../stdafx.h" #include ...

  6. @Autowired @Resource @Inject 自动注入

    一.@AutoWired ( spring 的注解 )自动注入 /** * @Autowired: * 默认按照 Student 类型去容器中找对应的组件:applicationContext.get ...

  7. MySQL多线程数据导入导出工具Mydumper

    http://afei2.sinaapp.com/?p=456 今天在线上使用mysqldump将数据表从一个库导入到另外一个库,结果速度特别慢,印象中有个多线程的数据导入导出工具Mydumper,于 ...

  8. SQL优化的思路及基本原则(mysql)

    SQL优化的思路:  1.优化更需要优化的sql:  2.定位优化对象的性能瓶颈:优化前需了解查询的瓶颈是IO还是CPU,可通过PROFILING很容易定位查询的瓶颈.  3.明确优化目标:  4.从 ...

  9. redis代码解析-事务

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

  10. [HTML5] Semantics for accessibility

    For example, when we use checkbox, if we do like this: <div class="inline-control sign-up co ...