Академический Документы
Профессиональный Документы
Культура Документы
h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/msg.h>
#include<sys/ipc.h>
#include<sys/types.h>
struct msg_st{
};
int buffer[MSGSZ];
int main()
{
int msgid;
struct msg_st *mymessage; //a pointer to the stucture that holds the message
int i = 0;
if ( msgid == -1)
{
printf("\nmsgget failed");
exit(EXIT_FAILURE);
}
/*
* Now that the message stucture is ready receive the message
*/
while(i<2)
{
if ( msgrcv(msgid,(void*)mymessage,MSGSZ*sizeof(int),1,0) == -1)
{
printf("\nmsgrcv failed");
exit(EXIT_FAILURE);
}
buffer[i] = mymessage->text[0];
i++;
printf("\nSum = %d\n",buffer[0]+buffer[1]);
/*
* Done. Now delete the msgQ
*/
if ( msgctl(msgid,IPC_RMID,0) == -1)
{
printf("\nmsgctl failed");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);