Advertisement
Guest User

Untitled

a guest
May 28th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdlib.h> #include <stdio.h> #define PUSTY 1 #define PELNY 2 struct elem{ long type; int val; }; main(int argc, char* argv[]){ int msgid, licz, licz2; struct elem el; msgid = msgget(45280, IPC_CREAT|IPC_EXCL|0777); if (msgid == -1){ msgid = msgget(45280, IPC_EXCL|0777); if (msgid == -1){ perror("Tworzenie"); exit(1); } perror("Przed tworzeniem"); exit(1); } else{ //write(1, "Podaj typ: ", 12); //read(0, i[1], 1); // el.val = 123; for (licz = 0; licz < 5; licz++){ el.val = licz; el.type = PUSTY; if (msgsnd(msgid, &el, sizeof(el.val), 0) == -1){ perror("Wysylanie"); exit(1); } printf("Wysylam!\n"); } for (licz2 = licz; licz2 < 9; licz2++){ el.val = licz2; el.type = PELNY; if (msgsnd(msgid, &el, sizeof(el.val), 0) == -1) { perror("Wysylanie"); exit(1); } } } //for (licz = 0; licz < 9; licz++){ // if (msgrcv(msgid, &el, sizeof(el.val), argc, 0) == -1){ while (msgrcv(msgid, &el, sizeof(el.val), argc, 0) > 1) { // perror("Odbieranie"); // exit(1); printf("Numer: %5d \nWartość: %5d\n", el.val, el.type); } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement