?? p9.4.c
字號(hào):
#include <stdio.h>#include <errno.h>#include <unistd.h>#include <fcntl.h>int main(int argc,char* argv[]){ int fd; int lock_result; struct flock lock; if(argc!=2){ printf("Usage: %s lock_file_name\n",argv[0]); return 1; } fd=open(argv[1],O_RDWR); if(fd<0){ perror("cannot open the file"); return 1; } lock_result=lockf(fd,F_LOCK,0); if(lock_result==-1){ perror("cannot get the lock...."); return 0; } printf("pid: %ld process lock the file\n",(long)getpid()); sleep(1); printf("pid: %ld process release the file\n",(long)getpid()); return 0;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -