|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: May 2006
Città: Enna
Messaggi: 105
|
[C] Segmentation fault dove sbaglio???
ciao ragazzio ho un problema con la memoria condivisa, il programma viene compilato senza nessun errore ma da Segmentation fault in fase d'esecuzione
ecco la porzione di codice Codice:
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <string.h> struct area_condivisa { int contatore; char messaggio[10]; }; int shmid; struct area_condivisa *shmaddr; int main(){ key_t area; shmid = shmget(area, sizeof(struct area_condivisa), IPC_CREAT); if (shmid < 0) { perror("La shared memory non e' stata creata \n"); exit(1); } shmaddr = (struct area_condivisa *) shmat (shmid, 0, SHM_RND); if (shmid < 0) { perror("Errore nella funzione Shmat \n"); exit(1); } strcpy(shmaddr->messaggio, "@@PROVA@@"); printf("##%s## \n",shmaddr->messaggio); }
__________________
Sony Vaio SB 13,3", Intel Core i5 2410M 2,30GHz, SandyBridge HM65, 8GB RAM 1333MHz, Crucial M4 128GB SATA III, AMD Radeon HD 6470M, Windows 7 x64 ![]() |
![]() |
![]() |
![]() |
#2 | |
Member
Iscritto dal: May 2006
Città: Enna
Messaggi: 105
|
Quote:
Problema risolto avevo dimenticato di dare i permessi - shmid = shmget(area, sizeof(struct area_condivisa), IPC_CREAT); + shmid = shmget(area, sizeof(struct area_condivisa), IPC_CREAT | 0666);
__________________
Sony Vaio SB 13,3", Intel Core i5 2410M 2,30GHz, SandyBridge HM65, 8GB RAM 1333MHz, Crucial M4 128GB SATA III, AMD Radeon HD 6470M, Windows 7 x64 ![]() |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 06:12.