⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locklink.c

📁 让你了解Unix进程间的通信是如何实现的
💻 C
字号:
#include	"unpipc.h"#define	LOCKFILE	"/tmp/seqno.lock"#define	PREFIX		"/tmp"		/* prefix for temp pathname */voidmy_lock(int fd){	char	*ptr;	ptr = tempnam(PREFIX, NULL);		/* create/open and then close */	Close(Open(ptr, O_CREAT | O_RDWR | O_TRUNC, FILE_MODE));	while (link(ptr, LOCKFILE) < 0) {		if (errno != EEXIST)			err_sys("link error for lock file");		/* someone else has the lock, loop around and try again */	}	Unlink(ptr);			/* linked the file, we have the lock */	free(ptr);				/* tempnam() calls malloc() */}voidmy_unlock(int fd){	Unlink(LOCKFILE);		/* release lock by removing file */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -