1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <errno.h>
#include <string.h>
#define CLE 456
int main (void){
struct mybuf{
long mtype;
char mtext[100];
}
msgp;
struct mybufReception{
long mtype;
char mtext[100];
}
msgpReception;
int msqid ; /* identificateur de la file de message */
char *path = "projet_cli_serv";
key_t idClef=ftok (path, (key_t) CLE);
msqid = msgget(idClef, 666|IPC_CREAT);
if( (msqid==-1)){
perror("file deja cree");
}
printf (" identificateur de la file : %d\n", msqid);
printf ("clé de l'ensemble : %d\n", idClef);
strcpy(msgp.mtext, "helloworld");
msgp.mtype=1;
printf("voici %s\n", msgp.mtext);
msgsnd(msqid, &msgp, sizeof(long)+sizeof(msgp.mtext), 0);
msgrcv(msqid, &msgpReception, 254, 1, 0);
printf("\nvoici ce que je viens de retirer de la file : %s....\n", msgpReception.mtext);
msgctl(msqid, IPC_RMID, NULL);
return 0;
} |
Partager