Skip to content

Instantly share code, notes, and snippets.

@krishnenc
Created May 26, 2011 07:39
Show Gist options
  • Save krishnenc/992724 to your computer and use it in GitHub Desktop.
Save krishnenc/992724 to your computer and use it in GitHub Desktop.
Creating and releasing a lock file
#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