#include #include #include #include #include "common.h" int main() { int qid = msgget(QUEUE_KEY, 0666); if (qid == -1) { perror("msgget (сервер не запущен?)"); return 1; } // подсказка только при вводе с клавиатуры int tty = isatty(STDIN_FILENO); float x; if (tty) { printf("Введите число: "); fflush(stdout); } while (scanf("%f", &x) == 1) { struct message req = {TYPE_REQUEST, getpid(), x}; if (msgsnd(qid, &req, MSG_SIZE, 0) == -1) { perror("msgsnd"); return 1; } struct message ans; // Ответ предназначен только нам: тип сообщения равен нашему PID if (msgrcv(qid, &ans, MSG_SIZE, getpid(), 0) == -1) { perror("msgrcv"); return 1; } printf("Ответ сервера: %g\n", ans.value); if (tty) { printf("Введите число: "); fflush(stdout); } } if (tty) printf("\n"); return 0; }