summaryrefslogtreecommitdiff
path: root/tools/pkg/3/pthread_test/shm_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pkg/3/pthread_test/shm_test.c')
-rw-r--r--tools/pkg/3/pthread_test/shm_test.c46
1 files changed, 0 insertions, 46 deletions
diff --git a/tools/pkg/3/pthread_test/shm_test.c b/tools/pkg/3/pthread_test/shm_test.c
deleted file mode 100644
index 5a66d37..0000000
--- a/tools/pkg/3/pthread_test/shm_test.c
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <string.h>
-
-#define SHM_SIZE 1024 // size of shared memory segment
-
-int main() {
- key_t key;
- int shmid;
- char *shmaddr;
-
- // Generate a unique key for shared memory
- key = 100;
-
- // Create shared memory segment with shmget()
- shmid = shmget(key, SHM_SIZE, IPC_CREAT | 0644);
- if (shmid == -1) {
- perror("shmget");
- exit(1);
- }
- printf("Shared memory ID: %d\n", shmid);
-
- // Attach to the shared memory segment with shmat()
- shmaddr = (char*) shmat(shmid, NULL, 0);
- if (shmaddr == (char*) -1) {
- perror("shmat");
- exit(1);
- }
-
- // Write to shared memory
- strcpy(shmaddr, "Hello from shared memory!");
-
- printf("Data written to shared memory: %s\n", shmaddr);
-
- // Detach from shared memory with shmdt()
- if (shmdt(shmaddr) == -1) {
- perror("shmdt");
- exit(1);
- }
-
- // Note: To remove the shared memory segment, use shmctl(shmid, IPC_RMID, NULL);
-
- return 0;
-} \ No newline at end of file