-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32d.c
More file actions
36 lines (32 loc) · 1.05 KB
/
32d.c
File metadata and controls
36 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
============================================================================
Name : 32d
Author : Piyush Singh
Description : Write a program to implement semaphore to protect any critical section.
a. rewrite the ticket number creation program using semaphore
b. protect shared memory from concurrent write access
c. protect multiple pseudo resources ( may be two) using counting semaphore
d. remove the created semaphore
Date: 26th Sep, 2025.
============================================================================
*/
// Semaphore Cleanup Program (macOS-compatible)
// <stdio.h> → printf()
// <semaphore.h> → sem_unlink()
// <fcntl.h> → required for POSIX semaphore flags
#include <stdio.h>
#include <semaphore.h>
#include <fcntl.h>
int main()
{
sem_unlink("/ticket_sem");
sem_unlink("/shared_sem");
sem_unlink("/resource_sem");
printf("🗑️ All named semaphores removed.\n");
return 0;
}
/*
Output:
╰─ ./32d ─╯
🗑️ All named semaphores removed.
*/