Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #define SHM_SIZE 1024
- int main()
- { key_t key;
- int shmid;
- char *VC;
- key = 100;
- if ((shmid = shmget(key, SHM_SIZE, 0644 | IPC_CREAT)) == -1) {
- perror("Ocorreu um erro em shmget");
- exit(1);
- }
- VC = shmat(shmid, (void *)0, 0);
- if (VC == (char *)(-1)) {
- perror("Erro em shmat");
- exit(1);
- }
- printf("\n Tecle enter p/ ver o valor inicial da variavel:");
- getchar();
- printf(" VC: [%s] \n",VC);
- printf("\n Tecle enter modificar o valor da variavel:");
- getchar();
- printf("Digite o novo valor de VC:");
- gets(VC);
- printf(" VC: [%s] \n",VC);
- printf("\n Tecle enter para ver novamente o valor da variavel:");
- getchar();
- printf(" Novo valor de VC: [%s] \n",VC);
- if (shmdt(VC) == -1) {
- perror("Erro em shmdt");
- exit(1);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment