-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise_05_01.c
More file actions
42 lines (35 loc) · 815 Bytes
/
Copy pathexercise_05_01.c
File metadata and controls
42 lines (35 loc) · 815 Bytes
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
37
38
39
40
41
42
#include "osheader.h"
int main(int argc, char** argv) {
key_t key = 12345;
size_t size = 128;
int smID;
int* adress;
// Create shared memory
if((smID = shmget(key, size, IPC_CREAT | IPC_EXCL)) == -1) {
perror("shmget failed\n");
exit(EXIT_FAILURE);
}
// Attach shared memory
if((adress = shmat(smID, NULL, 0)) == -1) {
perror("shmat failed\n");
exit(EXIT_FAILURE);
}
/*
memcpy(&adress, 0 , sizeof(int));
if((FILE* resultFifo = mkfifo("RESULT_FIFO", O_CREAT | 0666 )) == -1) {
perror("mkfifo failed\n");
exit(EXIT_FAILURE);
}
*/
// Detach shared memory
if(shmdt(adress) == -1) {
perror("shmdt\n");
exit(EXIT_FAILURE);
}
// Delete shared memory
if(shmctl(smID, IPC_RMID, NULL ) == -1) {
perror("shmctl failed\n");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}