Witam,
Mam problem z prostymi programami opartymi na kolejkach komunikatów. Jeden wysyła komunikaty, drugi odbiera:
typedef struct buf{
long pid;
char a[10];
}buf;
int main(){
buf bufor;
char abc[10];
int id;
int run =1;
bufor.pid = 1;
id = msgget(2122,IPC_CREAT|0600);
while(run){
scanf ("%s", bufor.a);
if(msgsnd(id,&bufor, sizeof(buf)-sizeof(long),0)==-1){
printf("nie");
}
if(strcmp(bufor.a,"end")==0){
run =0;
}
}
}
typedef struct buf{
long pid;
char a[10];
}buf;
int main(){
buf bufor;
int id;
int run=1;
char buf2[10];
id = msgget(2122,IPC_CREAT|0600);
while(run){
if(msgrcv(id, &bufor, sizeof(buf)-sizeof(long),0, 0)!=-1){
printf("%s",bufor.a);
if(strcmp(bufor.a,"end")==0){
run =0;
}
}
}
}
Problem jest następujący: komunikaty wyświetlają się dopiero po zakończeniu pracy programu (end), a nie kolejno tj. wysyłam komunikat -> odbieram -> wyświetlam. Wiecie może w czym tkwi problem?