Untitled
unknown
plain_text
3 years ago
742 B
9
Indexable
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<stdio.h>
struct msgbuf { //struktura komunikatu
long mtype; //typ komunikatu
int mnumber; //tresc komunikatu
};
struct msgbuf bufor;
int main()
{
int id_msgget, id_ftok; //identyfikator kolejki
id_ftok = ftok("zad3a.c",120);
id_msgget = msgget(id_ftok, IPC_CREAT|0660);
printf("Id msgget %d\n", id_msgget);
bufor.mtype = 1; //typ komunikatu
bufor.mnumber = 5; //tresc komunikatu
int rozmiar = sizeof(struct msgbuf) - sizeof(bufor.mtype); //rozmiar komunikatu
int wyslanie = msgsnd (id_msgget, &bufor, rozmiar, 0); //wyslanie komunikatu
if (wyslanie == -1)
perror("Blad wyslania");
printf("Wyslano komunikat: %d\n", bufor.mnumber);
return 0;
}Editor is loading...