Standalone Single Instance in Linux

Given code will help to create standalone single instance of application in Linux operating system.

#include <stdio.h>
#include <semaphore.h>
#include <fcntl.h>

int main()
    const char sem_name[] = “tmp”;
    sem_t * mutex;

    printf(“semaphore application started!\n”);
    mutex = sem_open(sem_name, O_CREAT | O_EXCL, 0600, 0);
    if(mutex == SEM_FAILED)
        printf(“semaphore FAILED!\n”);
        printf(“Named Semaphore CREATED!\n”);
        printf(“semaphore UNLINK!\n”);
    return 0;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s