博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lockf
阅读量:7293 次
发布时间:2019-06-30

本文共 1423 字,大约阅读时间需要 4 分钟。

lockf( fd, mode, size );

mode 为 1 时表示加锁,为 0 时表示解锁。

#include
#include
#include
#include
#include
int main(){ pid_t pid; int retval; char buf[6] = "hello"; if( (pid = fork() )< 0 ) { printf("fork error\n"); exit(-1); } else if( pid == 0 ) { while(1) { if( lockf(1,1,0) < 0 ) { printf("lockf on error\n"); exit(-1); } sleep(1); printf("this is in child!\n"); sleep(1); printf("this is in child!\n"); if( lockf(1,0,0) <0 ) { printf("lockf off error\n"); exit(-1); } sleep(1); } printf("this is child end\n"); exit(-1); } //wait(&retval); while(1) { if( lockf(1,1,0) < 0 ) { printf("lockf on error\n"); exit(-1); } sleep(1); printf("this is in parent!\n"); sleep(1); printf("this is in parent!\n"); if( lockf(1,0,0) <0 ) { printf("lockf off error\n"); exit(-1); } sleep(1); } printf("this is parent process end\n"); return 0;}

 

转载于:https://www.cnblogs.com/little-snake/p/4922521.html

你可能感兴趣的文章
第四十一课、编辑交互功能的实现------------------狄泰软件学院
查看>>
cocos2d-x之监听手机的物理按键
查看>>
python数据处理excel和pdf,并打包成exe
查看>>
基于 HTML5 WebGL 的低碳工业园区监控系统
查看>>
如何使绝对定位内部元素不继承父级宽度,而是靠内容自动撑开宽度(转载)
查看>>
《程序猿的生命周期》阅读有感
查看>>
重温排序算法
查看>>
Instrumentation 功能介绍(javaagent)
查看>>
Core J2EE Patterns - Data Access Object
查看>>
SpringCloud学习成长之路 六 cloud配置中心
查看>>
MyEclipse定位class文件
查看>>
STM32(HY-SRF05)超声波测距项目
查看>>
《practical Java》读书笔记
查看>>
数据库字段顺序的【坑】
查看>>
spring5新响应式框架-webflux实战
查看>>
软甲架构笔记 三
查看>>
STL training (uva上一些比较好的用来熟悉STL)
查看>>
[未完成]关于CSS的总结
查看>>
陈皓一起写Makefile 概述
查看>>
linux下安装启动rpc服务
查看>>