-
Notifications
You must be signed in to change notification settings - Fork 0
/
procA.c
46 lines (33 loc) · 897 Bytes
/
procA.c
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
44
45
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#define BUFF 128
#define RCVTYPE 16
#define SNDTYPE 17
typedef struct msgp {
long mtype;
char mtext[BUFF];
}msgp;
int main(int argc, char* argv[])
{
key_t cle;
int msgid;
msgp unMessage;
if ( ( cle = ftok("/home/azman/ed34/test",17 ) ) == -1)
perror("ftok"), exit(1);
printf("\n cle : %d\n", cle);
unMessage.mtype = SNDTYPE;
strcpy(unMessage.mtext, "Je suis le processus A");
if ( ( msgid = msgget(cle, IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR|S_IROTH|S_IWOTH )) == -1 )
perror("msgget"), exit(1);
printf("\n msgid: %d\n", msgid);
msgsnd(msgid, &unMessage, strlen(unMessage.mtext),0);
msgrcv(msgid, &unMessage, BUFF, RCVTYPE, MSG_NOERROR);
printf("ProcA: Message reçu: %s", unMessage.mtext);
exit(EXIT_SUCCESS);
}