-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc2.c
More file actions
35 lines (28 loc) · 815 Bytes
/
proc2.c
File metadata and controls
35 lines (28 loc) · 815 Bytes
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
/*
* proc2.c
* Работа с очередью сообщений IPC SysV
* Created on: 16.01.2018
* Author: jake
*/
#include <sys/types.h>
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
int main(void)
{
key_t ipckey;
int msgid;
struct {
long mtype;
char mtext[256];
} msg;
memset(msg.mtext, 0, 256); /* Clear out the space */;
ipckey = ftok("/home/jake/123.txt",'A');//генерация ключа
msgid = msgget(ipckey,0); //присоединение к очереди
msgrcv(msgid,&msg,256,-5L,0);//получение сообщения
msg.mtype=6L;//создание ответного сообщения
strcat(msg.mtext, "Hello, proc1!\n");
msgsnd(msgid,&msg,256,0);//отправка ответного сообщения
return 0;
}