C IO programming test code
#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的更多相关文章
- [IoLanguage]Io Programming Guide[转]
Io Programming Guide Introduction Perspective Getting Started Downloading Installing Binaries Ru ...
- hackr.io & Programming Courses & Programming Tutorials
hackr.io & Programming Courses & Programming Tutorials the Best Programming Courses & Tu ...
- 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 ...
- 大家是怎么做Code Review的?
先说说我们公司现在的做法,一个团队被人为地分为两个阵营:Senior Developers和Junior Developers,比例差不多是1:1,Senior Developers就担负着对Juni ...
- net programming guid
Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...
- 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 ...
- 如何在Etherscan.io 部署ETH以太坊智能合约 如何在15分钟内创建你的加密货币
一.概述 ETH 网络这里就不介绍了,这篇文章主要记录在以太坊主网和测试网络部署一个智能合约,也就是如何发币. 二.部署合约需要的生产工具 准备工具前,建议大家准备个VPN,因为会访问国外网 ...
- 如何用Git.io来生成自定义后缀名的短网址
如何用Git.io来生成自定义后缀名的短网址 git.io是Github的官方短网址,它是用来缩短Github上项目的网址. 效果:Git.io/wacsh将会跳转到https://xhemj.git ...
- .net Framework Class Library(FCL)
from:http://msdn.microsoft.com/en-us/library/ms229335.aspx 我们平时在VS.net里引用的那些类库就是从这里来的 The .NET Frame ...
随机推荐
- VS2008集成QT的OpenGL开发(实现二维图形的旋转)
主要是利用Qt中的定时器实现了二维图形的旋转功能: #ifndef QGLTEST_H #define QGLTEST_H #include <QGLWidget> #include &l ...
- 小结ajax中的同源和跨域 jsonp和cors
网上的同源和跨域一般都比较复杂,最近也稍微总结了一下: 所谓同源,是浏览器的一种安全机制,作用在于保护网页数据的安全,不同源的网页之间不允许cookie dom ajax等行为 同源的条件:1.协议相 ...
- CSS 居中【整合】
<center> text-align:center 在父容器里水平居中 inline 文字,或 inline 元素 vertical-align:middle 垂直居中 inline 文 ...
- Python设计模式--单例模式(懒汉式)
1. 单例模式 --> 单一(唯一)的实例. 在整个运行时间内, 内存中只有一个对象, 一般该对象涉及网络,资源等操作. 2. 单例模式一般分为懒汉式和饿汉式 懒汉式内存占用更加合理. 3. 调 ...
- Ubuntu双系统后时间不对解决方案
先在ubuntu下更新一下时间,确保时间无误 sudo apt install ntpdate sudo ntpdate time.windows.com 然后将时间更新到硬件上 sudo hwclo ...
- Mysql学习总结(37)——Mysql Limit 分页查询优化
select * from table LIMIT 5,10; #返回第6-15行数据 select * from table LIMIT 5; #返回前5行 select * from table ...
- 计算机网络系统--TCP/IP OSI模型
- cogs 1143. [石门中学2009] 切割树
1143. [石门中学2009] 切割树 ★ 输入文件:treecut.in 输出文件:treecut.out 简单对比时间限制:1 s 内存限制:128 MB treecut 题目描 ...
- 分布式公布订阅消息系统 Kafka 架构设计
我们为什么要搭建该系统 Kafka是一个消息系统,原本开发自LinkedIn,用作LinkedIn的活动流(activity stream)和运营数据处理管道(pipeline)的基础. 如今它已为多 ...
- Bridge模式
Bridge模式 Bridge模式 在面向对象的开发过程中,要做到2点:1.高内聚(cohesion).2.松耦合(coupling).可是在实际开发过程中难以把握,比如会遇到这种问题: 1)客户给了 ...