Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/wait.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8.  
  9. #define chiave 9876
  10. // id shared memory (definito dal sistema operativo)
  11. int s1;
  12.  
  13. // indirizzo del segmento di memoria collegato
  14. // al spazio di indirizzamento del processo
  15. int *pointer;
  16.  
  17. int main(void) {
  18.  
  19. pid_t figlio;
  20. int status;
  21.  
  22. s1 = shmget(chiave, sizeof(int), 0666);
  23. pointer = (int*) shmat(s1,NULL,0);
  24.  
  25. *pointer = 1;
  26.  
  27. if((figlio = fork()) == 0) {
  28. char *args[1] = {NULL};
  29. execvp("ciao", args);
  30.  
  31. }
  32. else {
  33. //padre
  34. wait(&status);
  35. printf("\n il figlio ha finito \n");
  36. printf("%i", *pointer);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement