Hi there... I have the msgsnd code:

(...)
char *c1="./df";
if(!(df=(FILE*)popen(c1,"r"))){fprintf(stderr,"pipe1 problem");}
s1.mtype=1;
while(true){
time3=time(NULL);
	if((time3-time4)>3){
	fgets(s1.mtext,1000,df);
	time4=time3;
if(msgsnd(msqid,&s1,1000,msgflg)<0){fprintf(stderr,"sending1 problem\n"); perror("g");};}
}
}
else if(pID1<0){
printf("failed to fork1\n");}
else{
prid2 = nproc2();}
return pID1;
}

and the msgrcv code

msgbuf rcv;
while(true){
time1=time(NULL);
if((time1-time2)>1){time2=time1; if(msgrcv(msqid,&rcv,1000,1,msgflg)<0){fprintf(stderr,"rcv problem");};printf("%d : %s\n",time1,rcv.mtext);}}}
return pID3;
}

But i wanted to change this code to wrtite on the screen whole "df" content and not line by line.
I changed it into:

(...)char *c1="./df";
if(!(df=(FILE*)popen(c1,"r"))){fprintf(stderr,"pipe1 problem");}
s1.mtype=1;
	fgets(s1.mtext,1000,df);
if(msgsnd(msqid,&s1,1000,msgflg)<0){fprintf(stderr,"sending1 problem\n"); perror("g");}
}
else if(pID1<0){
printf("failed to fork1\n");}
else{
prid2 = nproc2();}
return pID1;(...)
msgbuf rcv;
if(msgrcv(msqid,&rcv,1000,1,msgflg)<0){fprintf(stderr,"rcv problem");};printf("%d : %s\n",time1,rcv.mtext);}}
return pID3;}

I know that 1000 is not enough length. But when i compile it and run it gives me the segmentation fault... do u know where could be a problem ?

I'm not currently running a Unix build, but aren't msgrcv/msgsnd routines extremely sensitive to correct buffer size? What line, which call, causes the error?

This article has been dead for over six months. Start a new discussion instead.