#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
typedef struct msgbuf {
long mtype;
FILE *mtext;
} message_buf;
main(){
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
if ((msqid = msgget(key, msgflg )) < 0){
perror("msgget");
exit(1);
}
sbuf.mtype = 1;
sbuf.mtext = popen("df", "r");
buf_length = strlen(sbuf.mtext) + 1;
if(msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) {
printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
exit(1);
}
else
printf(sbuf.mtext);
exit(0);
}
Hi there, this is my code, i have a problem like that in the topic. I dunno where is the problem, anyone see anything ?