Guest User

Untitled

a guest
Oct 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sys/ipc.h>
  6. #include <sys/shm.h>
  7. #define SHM_SIZE 1024
  8. int main()
  9. { key_t key;
  10. int shmid;
  11. char *VC;
  12.  
  13. key = 100;
  14.  
  15. if ((shmid = shmget(key, SHM_SIZE, 0644 | IPC_CREAT)) == -1) {
  16. perror("Ocorreu um erro em shmget");
  17. exit(1);
  18. }
  19.  
  20.  
  21. VC = shmat(shmid, (void *)0, 0);
  22. if (VC == (char *)(-1)) {
  23. perror("Erro em shmat");
  24. exit(1);
  25. }
  26.  
  27. printf("\n Tecle enter p/ ver o valor inicial da variavel:");
  28. getchar();
  29. printf(" VC: [%s] \n",VC);
  30.  
  31. printf("\n Tecle enter modificar o valor da variavel:");
  32. getchar();
  33. printf("Digite o novo valor de VC:");
  34. gets(VC);
  35. printf(" VC: [%s] \n",VC);
  36.  
  37. printf("\n Tecle enter para ver novamente o valor da variavel:");
  38. getchar();
  39. printf(" Novo valor de VC: [%s] \n",VC);
  40.  
  41. if (shmdt(VC) == -1) {
  42. perror("Erro em shmdt");
  43. exit(1);
  44. }
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment