#include #include #include #include #include #include #define BUFF_SIZE 1024 typedef struct { int statusz; char buff[BUFF_SIZE]; } comm_t; #define SHMSZ (sizeof(comm_t)) #define KLIENSRE_VARUNK 0 #define SZERVERRE_VARUNK 1 main() { char c, x; int shmid; key_t key; comm_t *comm = NULL; char temp[512]; int length = 0; FILE *f; key = 5555; if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { perror("shmget"); exit(1); } if ((comm = shmat(shmid, NULL, 0)) == (char *) -1) { perror("shmat"); exit(1); } while (1) { while (comm->statusz != KLIENSRE_VARUNK) sleep(1); // Ha visszaadott vmit, kiirjuk (elso futasnal NULL lesz benne a memset miatt if (strlen(comm->buff)) printf("Ezt kaptuk: '%s'\n", comm->buff); fgets(comm->buff, BUFF_SIZE, stdin); // beolvassuk // \n\r vagy \r\n t kiszedjuk vegerol if (strchr(comm->buff, '\n')) *strchr(comm->buff, '\n') = NULL; if (strchr(comm->buff, '\r')) *strchr(comm->buff, '\r') = NULL; comm->statusz = SZERVERRE_VARUNK; } }