Coder Social home page Coder Social logo

linux-ipc-message-queues's Introduction

Linux-IPC-Message-Queues

Linux IPC-Message Queues

AIM:

To write a C program that receives a message from message queue and display them

DESIGN STEPS:

Step 1:

Navigate to any Linux environment installed on the system or installed inside a virtual environment like virtual box/vmware or online linux JSLinux (https://bellard.org/jslinux/vm.html?url=alpine-x86.cfg&mem=192) or docker.

Step 2:

Write the C Program using Linux message queues API

Step 3:

Execute the C Program for the desired output.

PROGRAM:

C program that receives a message from message queue and display them

// C Program for Message Queue (Writer Process) #include <stdio.h> #include <sys/ipc.h> #include <sys/msg.h>

// structure for message queue struct mesg_buffer { long mesg_type; char mesg_text[100]; } message; int main() { key_t key; int msgid; // ftok to generate unique key key = ftok("progfile", 65); // msgget creates a message queue // and returns identifier msgid = msgget(key, 0666 | IPC_CREAT); message.mesg_type = 1; printf("Write Data : "); gets(message.mesg_text); // msgsnd to send message msgsnd(msgid, &message, sizeof(message), 0); // display the message printf("Data send is : %s \n", message.mesg_text); return 0; }

// C Program for Message Queue (Reader Process) #include <stdio.h> #include <sys/ipc.h> #include <sys/msg.h>

// structure for message queue struct mesg_buffer { long mesg_type; char mesg_text[100]; } message; int main() { key_t key; int msgid; // ftok to generate unique key key = ftok("progfile", 65); // msgget creates a message queue // and returns identifier msgid = msgget(key, 0666 | IPC_CREAT); // msgrcv to receive message msgrcv(msgid, &message, sizeof(message), 1, 0); // display the message printf("Data Received is : %s \n", message.mesg_text);

// to destroy the message queue
msgctl(msgid, IPC_RMID, NULL);
return 0;

}

OUTPUT

$ ./writer.o Write Data : Helloworld Data send is : Helloworld

$ ./reader.o Data Received is : Helloworld

$ ipcs ------ Message Queues -------- key msqid owner perms used-bytes messages
0xffffffff 720896 gganesh 666 560 5

------ Shared Memory Segments -------- key shmid owner perms bytes nattch status
0x00000000 262144 gganesh 600 33554432 2 dest
0x00000000 360449 gganesh 600 524288 2 dest
0x00000000 688130 gganesh 600 524288 2 dest
0x00000000 622595 gganesh 600 524288 2 dest
0x00000000 786436 gganesh 600 524288 2 dest
0x00000000 655365 gganesh 600 524288 2 dest
0x00000000 983046 gganesh 600 524288 2 dest

------ Semaphore Arrays -------- key semid owner perms nsems

RESULT:

The programs are executed successfully.

linux-ipc-message-queues's People

Contributors

gowriganeshns avatar jidheshp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.