Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Link with pthread support - gcc -pthread -o A A.c
- #include <errno.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <semaphore.h>
- #include <stdio.h>
- #define SEM_NAME "/sample_app_semaphore"
- int main()
- {
- sem_t *sem = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0666, 0);
- if (sem == SEM_FAILED)
- {
- if (errno == EEXIST)
- {
- puts("This application is already running.");
- return 1;
- }
- puts("Cannot create semaphore - it may already exist");
- return 2;
- }
- puts("Press any key...");
- getchar();
- sem_close(sem);
- sem_unlink(SEM_NAME);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement