I want all the children processes to write in a shared memory and the father then reads it, I have to introduce a series of characters in it, the first process writes 2 characters, the second the next 2 ... Then read this array by the father, just read well those of the first process.
padre.memCompartida = shmget(clavecompartida,sizeof(char*)*80 , IPC_CREAT | 0600);
clavecompartida = ftok("/tmp/acompartido",33);
if(padre.memCompartida==-1){
perror("Error al crear la memoria compartida\n");
exit(1);
}
padre.punteroMem = (char *) shmat(padre.memCompartida, NULL, 0);
if(padre.punteroMem==(char *)-1){
perror("Error en el puntero a la zona de memoria compartida\n");
exit(1);
}
//CREAR EL PROCESO PADRE Z de zacarias
int i;
for(i=0;i<NUM_HIJOS;i++)
{
switch(hijos[i].pid=fork())
{
case -1:
printf("hubo un error en la creacion de los hijos.\n");
return 3;
case 0:
//sleep(1);
//INICIALIZACION DE LOS PROCESOS
hijos[i].nombre=LETRAS[i];
switch(hijos[i].nombre){
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
case 'D':
case 'd':
hijos[i].grupo='1';
break;
case 'E':
case 'e':
case 'F':
case 'f':
case 'G':
case 'g':
case 'H':
case 'h':
hijos[i].grupo='2';
break;
case 'I':
case 'i':
case 'J':
case 'j':
case 'L':
case 'l':
case 'M':
case 'm':
hijos[i].grupo='3';
break;
case 'N':
case 'n':
case 'O':
case 'o':
case 'P':
case 'p':
case 'R':
case 'r':
hijos[i].grupo='4';
break;
}
hijos[i].memCompartida=padre.memCompartida
**hijos[i].punteroMem=padre.punteroMem;**
** padre.punteroMem[2*i]=hijos[i].nombre;**
** padre.punteroMem[i+1]=hijos[i].grupo;**
exit (0);
}
}
for(i=0;i<63;i++){
printf("%c",padre.punteroMemoria[i];
printf ("Precione ENTER para liberar los recursos compartidos\n");
getchar ();
shmctl (padre.memCompartida, IPC_RMID,(struct shmid_ds *)NULL);
} //FIN MAIN