#include "stdio.h" #include <stdlib.h> #include "sys/time.h" #include "unistd.h" #include "sys/types.h" #include "sys/ipc.h" #include "sys/shm.h" #include "sys/sem.h" #include "errno.h"
struct free_mem { struct free_mem *next_free; //puntero al siguiente nodo char *free; //puntero al bloque libre int size; // tamaño del bloque libre
};
char *seg_init, *disponible; int id_seg;
main(){ struct free_mem *p; p = (struct free_mem *)malloc(sizeof(struct free_mem));
//solicitamos memoria al sistema operativo. La funcion shmget retorna codigo del segmento de datos.
if((id_seg = shmget(IPC_PRIVATE, 4096, 0660)) == -1){ printf("Error"); return(-1); } // obtenemos el puntero a dicha memoria o segmento compartido
seg_init = (char *)shmat(id_seg, (char*) 0, 0); disponible = (char *)seg_init;
printf("0x%x ",seg_init); printf("0x%x \n",disponible);
p->free = disponible; p->next_free = NULL; }
|