Created
May 26, 2011 07:39
-
-
Save krishnenc/992724 to your computer and use it in GitHub Desktop.
Creating and releasing a lock file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fcntl.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#define PACKAGE "crlock" | |
//create the lock on the postgresql server | |
int logos_getlock_file() | |
{ | |
int fd = 0; | |
while(1) | |
{ | |
if((fd = open("/tmp/locked.file", O_RDWR|O_CREAT|O_EXCL, 0444)) == -1) { | |
} | |
else | |
return fd; | |
} | |
} | |
//release the lock on the postgresql server | |
void logos_releaselock_file(int fd) | |
{ | |
close(fd); | |
unlink("/tmp/locked.file"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment