Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zmodyfikuj programy z zadania trzeciego tak, aby zbada ć jak si ę b ę dzie
- zachowywa ł a funkcja msgrcv(), w zale ż no ś ci od tego, czy otrzyma flag ę
- IPC_NOWAIT, czy nie.
- */
- // Program pierwszy - wysylajacy wiadomosc
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <string.h>
- #include <errno.h>
- #define MESSAGE_TO_SEND "Wiadomosc do wyslania"
- #define FTOK_KEY 712
- #define BUFFER_SIZE 128
- struct msgbuf {
- long mtype;
- char mtext[BUFFER_SIZE];
- };
- int main(void)
- {
- int id;
- key_t key;
- struct msgbuf send_buffer;
- if((key = ftok("/tmp", FTOK_KEY)) == -1){
- perror("ftok");
- return EXIT_FAILURE;
- }
- if((id = msgget(key, 0600 | IPC_CREAT)) == -1){
- perror("msgget");
- return EXIT_FAILURE;
- }
- send_buffer.mtype = 1;
- memset(send_buffer.mtext, '\0', BUFFER_SIZE);
- strncpy(send_buffer.mtext, MESSAGE_TO_SEND, BUFFER_SIZE);
- for(int i = 0; i < 1000; i++){
- if(msgsnd(id, &send_buffer, sizeof(send_buffer.mtext), IPC_NOWAIT) == -1){
- if(errno == EAGAIN)
- printf("Blad dzieki ustawionej fladze IPC_NOWAIT: %s\n", strerror(errno));
- else
- perror("msgsnd");
- return EXIT_FAILURE;
- }
- }
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment