-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared_mem_sysvipc.c
72 lines (55 loc) · 1.38 KB
/
shared_mem_sysvipc.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int main (int argc, char* argv[]){
char *ptr, tmp;
char option;
int shm_id;
size_t size = 1024*1024*100;
size_t count;
shm_id=shmget(334,size,IPC_CREAT|0666);
if( shm_id < 0 ){
printf("Falha alocacao de memoria \n");
return 1;
}
ptr = shmat(shm_id,NULL,0);
if( (void *) ptr < 0 ){
printf("Falha em atachar memoria compartilhada \n");
return 1;
}
while(1){
printf("Acoes:\n (1)Exibir configuração atual\n (2)Alterar a configuração\n (3)Encerrar\n");
printf("Digite a opçao:");
option= (char) getchar();
while ((getchar()) != '\n');
switch(option){
case '1':
printf("Configuração atual:\n");
printf("%s\n",ptr);
for(count=0;count<size;count++){
tmp = *(ptr+count);
}
break;
case '2':
printf("Digite a nova configuração:\n");
fgets(ptr,size-1024,stdin);
printf("\n");
break;
case '3':
printf("\nEncerrando\n");
break;
default :
printf("\nInvalid Option");
}
if(option == '3'){
break;
}
}
shmdt(ptr);
shmctl(shm_id,IPC_RMID,NULL);
}