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
| #include "common.h"
int main() { int qid, fd; key_t key; message msg; char buff[BUFFER_SIZE];
key = ftok(".", 'a'); if (key == -1) { perror("ftok error"); exit(1); }
qid = msgget(key, IPC_CREAT | 0666); if (qid == -1) { perror("msgget error."); exit(1); }
fd = open("/dev/ttyS1", O_RDWR); if (fd == -1) { perror("open error."); exit(1); }
read(fd, buff, BUFFER_SIZE); strncpy(msg.msg_text, buff, strlen(buff)); msg.msg_type = getpid();
int size = msgsnd(qid, &msg, strlen(msg.msg_text), 0); if (size < 0) { perror("message posted."); exit(1); }
exit(0); }
|