-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSHM.c
More file actions
42 lines (33 loc) · 692 Bytes
/
SHM.c
File metadata and controls
42 lines (33 loc) · 692 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
struct SHM {
int shmid;
key_t key;
char *shm, *s;
};
struct SHM *SHM_new () {
struct *SHM shm;
shm = malloc(sizeof(struct SHM))
return shm;
}
SHM_malloc(size_t n){
key = 5678; // getkey
if ((shmid = shmget(key, n, IPC_CREAT | 0666)) < 0) {
perror("shmget");
return(-1);
}
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
perror("shmat");
return(-2);
}
}
int SHM_get(int key){
if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {
perror("shmget");
exit(1);
}
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
perror("shmat");
exit(1);
}
// shm lock
return shm;
}