O_APPEND:原子操作
摘要:
当多个进程打开同一个文件写入日志的时候,OPEN时指定了O_APPEND参数,UNIX能保证这个操作是原子的,程序不需要自己加锁/*log1.c*/#include<stdio.h>#include<string.h>#include<fcntl.h>#include<unistd.h>int Max = 300;int main(){ int i; int fd; fd = open("1.log",O_WRONLY | O_APPEND); for(i=0;i<Max;i++) { char msg[100]; sp 阅读全文
posted @ 2012-06-28 00:44 codestyle 阅读(891) 评论(0) 推荐(0)
浙公网安备 33010602011771号