SlideShare a Scribd company logo
1 of 14
UNIX

                            MESSAGE
                            QUEUES

                                      Reference:
Rohit Sinha                           Unix System Programming
2BV07CS081                            Using C++
http://www.rohitsinha.com                       -- Terrence Chan
MESSAGE QUEUES
• Linked list of messages
• Message queue table in kernel address
  space
• Identified by message queue identifier
KERNEL DATA STRUCTURE

                 •A name which
                Struct msqid_dsis anA MessageKey
                                        integer ID Queue
                {•A creator user ID and group ID
                 •Assigned owner user ID and group ID
                   struct ipc_perm msg_perm;
                 •Read-write access permission
                   msgqnum_t           msg_qnum;
                  of the queue for owners,
                   msglen_t             msg_qbytes;
                      Message Record others
                  group members and
                   pid_t                msg_lspid;
                 •Last read time and process ID
                   pid_t                msg_lrpid;
                 •Last write time and process ID
                   time_t               msg_stime
                 •Pointer to a linked list of message
                   time_t               msg_rtime
                  records.
                   time_t               msg_ctime
Message Table      :
                   :
                }
Kernel Handling Message
            Queue
                                       Sender
                                       Process




                     •Message type
                     •No of bytes of
                      message          Receiver
Message Table        •Pointer to       Process
                      actual
                      message data
            Actual
           Message
SYSTEM-IMPOSED LIMITS
                 <sys/msg.h>

  SYSTEM LIMIT                       Meaning

    MSGMNI               The maximum number of message
                         queue that may exists at any given
                                 time in a system


    MSGMAX               The maximum number of bytes of
                           data allowed for a message

    MSGMNB               The maximum number of bytes of
                         all messages allowed in a queue

    MSGTQL              The maximum number of messages
                         in all queues allowed in a system
APIs FOR MESSAGE
  MANIPULATION
            #include <sys/types.h>
            #include <sys/ipc.h>
            #include <sys/message.h>
MESSAGE API                            USES

  msgget                   Open and create if needed, a
                            message queue for access

  msgsnd                   Sends a message to message
                                     queue

   msgrcv               Receives a message from message
                                     queue

   msgctl                 Manipulate the control data of a
                                 message queue
MSGGET
• Prototype
     #include <sys/types.h>
     #include <sys/ipc.h>
     #include <sys/message.h>
     int msgget (key_t key, int flag);

                 Returns -1 when fails
• Opens a message queue with ID as key
     • If the key value is a manifested constant IPC_PRIVATE the API
       allocates a special message queue to be used exclusively by the
       calling process.
  – Flag can take two values:
     • 0: API aborts if there is no message queue whose key ID matches the given
       key value otherwise return a descriptor for that queue.
     • IPC_CREAT: Creates a new queue (if none exists) with given key ID and
       read-write access permission.
         – Ex: int msgfdesc = msgget(15, IPC_CREAT|0644);
             » IPC_EXCL ensures the API succeeds only if it creates a new msg queue.
MSGSND
• Prototype is a pointer to an object that contains the actual message
msgPtr: it
text and #include <sys/types.h> be sent
         and message type to
       #include <sys/ipc.h>
       #include <sys/message.h>
       int msgsnd (int msgfd, const void* msgPtr, int len, int flag);
                struct msgbuf
        Returns -1 when fails 0 on success
                {
•   Send a message pointed by msgPtr to a message
                         long mtype
    queue designated message type
                          //
                              by the msgfd descriptor
                         char mtext[MSGMAX]
•   The len value is the sizehold bytes of the message
                          // buffer to in the message text
                }
• Two values of flag:
     – 0: Process is blocked if needed until the process call is
          completed.
     – IPC_NOWAIT: Function abort if the process is to be
                        blocked ----- (EAGAIN)
MSGRCV

    • Prototype
              #include <sys/types.h>
              #include <sys/ipc.h>
              #include <sys/message.h>
If there is message in queuemsgfd, const void* msgPtr, criteria but mtype, int flag); the
              int msgrcv (int that satisfies the selection int len, int is larger than len,
       Success: Returns number of bytes written
function returns a failure status
     • Receive a message of type mtype from a message queue
If MSG_NOERROR is set in the flag value, a message-1 queue is selectable
                            Fail: Returns in the
        designated by the msgfd descriptor in an object pointed by the
        msgPtr
irrespective of length.
     • The len value is the max size in bytes of the message that can be
        received
     • Two values of flag:
         – 0: Process is blocked if no message in queue matched the selection
           criteria specified by mtype
         – IPC_NOWAIT: The call is non blocking (returns -1 with errno set to
           ENOMSG)
mtype Values
           (type of the message to be received)


 mtype values                             Meaning

       0                     Receive the oldest message of any
                                     type in the queue


Positive integer               Receive the oldest message of
                                  specified message type


Negative integer            Receive a message whose message
                               type is less than or equal to the
                            absolute value of mytpe. If more than
                            1 receive the oldest and the smallest.
MSGCTL
• Prototype
      #include <sys/types.h>
      #include <sys/ipc.h>
      #include <sys/message.h>
      int msgctl (int msgfd, int cmd, struct msqid_ds* mbufPtr);

                  Fail: returns -1
• Used to query the control data of a message queue
  designated by the msgfd:argument 0
              Success returns
• To change the information within the control data of
  the queue
• To remove a message queue
cmd Values
             cmd value                              Meaning

             IPC_STAT                  Copy control data of the queue to the
                                          object pointed by the mbufPtr

             IPC_SET                   Change the control data of the queue
                                         by those specified in the object
                                               pointed by mbufPtr

             IPC_RMID                   Remove the queue from the system


Note: The calling process for IPC_SET and IPC_RMID must be
      superuser, creator or the assigned owner of the queue.
CLIENT/SERVER EXAMPLE
THANK YOU


• Queries ?
  – Just Google it 

More Related Content

What's hot

Internetworking.49
Internetworking.49Internetworking.49
Internetworking.49myrajendra
 
Unicast multicast & broadcast
Unicast multicast & broadcastUnicast multicast & broadcast
Unicast multicast & broadcastNetProtocol Xpert
 
Transport services
Transport servicesTransport services
Transport servicesNavin Kumar
 
ELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOLELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOLShashank Rustagi
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)k33a
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesMeghaj Mallick
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dosvanamali_vanu
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocolsFabMinds
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
Middleware and Middleware in distributed application
Middleware and Middleware in distributed applicationMiddleware and Middleware in distributed application
Middleware and Middleware in distributed applicationRishikese MR
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Structure of shared memory space
Structure of shared memory spaceStructure of shared memory space
Structure of shared memory spaceCoder Tech
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithmBushra M
 
Tcpip services and applications
Tcpip services and applicationsTcpip services and applications
Tcpip services and applicationsOnline
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SHussain Ala'a Alkabi
 

What's hot (20)

Internetworking.49
Internetworking.49Internetworking.49
Internetworking.49
 
Unicast multicast & broadcast
Unicast multicast & broadcastUnicast multicast & broadcast
Unicast multicast & broadcast
 
Transport services
Transport servicesTransport services
Transport services
 
ELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOLELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOL
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed Databases
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
 
Sania rtp
Sania rtpSania rtp
Sania rtp
 
CoAP - Web Protocol for IoT
CoAP - Web Protocol for IoTCoAP - Web Protocol for IoT
CoAP - Web Protocol for IoT
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Process Management-Process Migration
Process Management-Process MigrationProcess Management-Process Migration
Process Management-Process Migration
 
Ooad presentatin crc cards
Ooad presentatin crc cardsOoad presentatin crc cards
Ooad presentatin crc cards
 
Encoding Techniques
Encoding TechniquesEncoding Techniques
Encoding Techniques
 
Middleware and Middleware in distributed application
Middleware and Middleware in distributed applicationMiddleware and Middleware in distributed application
Middleware and Middleware in distributed application
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Structure of shared memory space
Structure of shared memory spaceStructure of shared memory space
Structure of shared memory space
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
 
Tcpip services and applications
Tcpip services and applicationsTcpip services and applications
Tcpip services and applications
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.S
 

Viewers also liked

Do More With Message Queue
Do More With Message QueueDo More With Message Queue
Do More With Message QueueHean Hong Leong
 
МАИ, Сети ЭВМ, Лекция №6
МАИ, Сети ЭВМ, Лекция №6МАИ, Сети ЭВМ, Лекция №6
МАИ, Сети ЭВМ, Лекция №6Dima Dzuba
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queueBrandon Lamb
 
unix interprocess communication
unix interprocess communicationunix interprocess communication
unix interprocess communicationguest4c9430
 
INTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLS
INTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLSINTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLS
INTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLSJOLLUSUDARSHANREDDY
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPRabbit MQ
 
Data warehouse : Order Management
Data warehouse : Order ManagementData warehouse : Order Management
Data warehouse : Order ManagementKritiya Sangnitidaj
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQDmitriy Samovskiy
 
Life in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoLife in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoTareque Hossain
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKXMike Willbanks
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache KafkaJeff Holoman
 
Основы разработки требований по К.Вигерсу
Основы разработки требований по К.ВигерсуОсновы разработки требований по К.Вигерсу
Основы разработки требований по К.ВигерсуOlya Kollen, PhD
 
Q4M - a high-performance message queue for MySQL
Q4M - a high-performance message queue for MySQLQ4M - a high-performance message queue for MySQL
Q4M - a high-performance message queue for MySQLKazuho Oku
 

Viewers also liked (20)

Message queueing
Message queueingMessage queueing
Message queueing
 
Art Of Message Queues
Art Of Message QueuesArt Of Message Queues
Art Of Message Queues
 
Do More With Message Queue
Do More With Message QueueDo More With Message Queue
Do More With Message Queue
 
МАИ, Сети ЭВМ, Лекция №6
МАИ, Сети ЭВМ, Лекция №6МАИ, Сети ЭВМ, Лекция №6
МАИ, Сети ЭВМ, Лекция №6
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 
unix interprocess communication
unix interprocess communicationunix interprocess communication
unix interprocess communication
 
INTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLS
INTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLSINTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLS
INTERRUPT ROUTINES IN RTOS EN VIRONMENT HANDELING OF INTERRUPT SOURCE CALLS
 
JMS
JMSJMS
JMS
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQP
 
Django Celery
Django Celery Django Celery
Django Celery
 
Data visualization for e commerce of jcpenney
Data visualization for e commerce of jcpenneyData visualization for e commerce of jcpenney
Data visualization for e commerce of jcpenney
 
Data warehouse : Order Management
Data warehouse : Order ManagementData warehouse : Order Management
Data warehouse : Order Management
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQ
 
Life in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoLife in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with django
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKX
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Основы разработки требований по К.Вигерсу
Основы разработки требований по К.ВигерсуОсновы разработки требований по К.Вигерсу
Основы разработки требований по К.Вигерсу
 
Q4M - a high-performance message queue for MySQL
Q4M - a high-performance message queue for MySQLQ4M - a high-performance message queue for MySQL
Q4M - a high-performance message queue for MySQL
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar to Message queues

signals & message queues overview
signals & message queues overviewsignals & message queues overview
signals & message queues overviewVaishali Dayal
 
Usp message queues
Usp message queuesUsp message queues
Usp message queuesRohitK71
 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPTSowmya Jyothi
 
ipc.pptx
ipc.pptxipc.pptx
ipc.pptxSuhanB
 
System Programming - Interprocess communication
System Programming - Interprocess communicationSystem Programming - Interprocess communication
System Programming - Interprocess communicationHelpWithAssignment.com
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI IntroductionRohit Banga
 
Message authentication and hash function
Message authentication and hash functionMessage authentication and hash function
Message authentication and hash functionomarShiekh1
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationMohd Tousif
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYKathirvel Ayyaswamy
 
Mote Mote Radio Communication
Mote Mote Radio CommunicationMote Mote Radio Communication
Mote Mote Radio CommunicationAnkit Singh
 
Using message queues for distributed computing on Kubernetes
Using message queues for distributed computing on KubernetesUsing message queues for distributed computing on Kubernetes
Using message queues for distributed computing on KubernetesSelin Gungor
 
Inter process communication using Linux System Calls
Inter process communication using Linux System CallsInter process communication using Linux System Calls
Inter process communication using Linux System Callsjyoti9vssut
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAMaulik Borsaniya
 

Similar to Message queues (20)

signals & message queues overview
signals & message queues overviewsignals & message queues overview
signals & message queues overview
 
Usp message queues
Usp message queuesUsp message queues
Usp message queues
 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
 
6. TinyOS_2.pdf
6. TinyOS_2.pdf6. TinyOS_2.pdf
6. TinyOS_2.pdf
 
ipc.pptx
ipc.pptxipc.pptx
ipc.pptx
 
Cns
CnsCns
Cns
 
System Programming - Interprocess communication
System Programming - Interprocess communicationSystem Programming - Interprocess communication
System Programming - Interprocess communication
 
SNMP/SMTP/MIME
SNMP/SMTP/MIMESNMP/SMTP/MIME
SNMP/SMTP/MIME
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI Introduction
 
MPI
MPIMPI
MPI
 
25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
 
Kafka overview v0.1
Kafka overview v0.1Kafka overview v0.1
Kafka overview v0.1
 
Intake 37 12
Intake 37 12Intake 37 12
Intake 37 12
 
Message authentication and hash function
Message authentication and hash functionMessage authentication and hash function
Message authentication and hash function
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
 
Mote Mote Radio Communication
Mote Mote Radio CommunicationMote Mote Radio Communication
Mote Mote Radio Communication
 
Using message queues for distributed computing on Kubernetes
Using message queues for distributed computing on KubernetesUsing message queues for distributed computing on Kubernetes
Using message queues for distributed computing on Kubernetes
 
Inter process communication using Linux System Calls
Inter process communication using Linux System CallsInter process communication using Linux System Calls
Inter process communication using Linux System Calls
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
 

Recently uploaded

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

Recently uploaded (20)

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

Message queues

  • 1. UNIX MESSAGE QUEUES Reference: Rohit Sinha Unix System Programming 2BV07CS081 Using C++ http://www.rohitsinha.com -- Terrence Chan
  • 2. MESSAGE QUEUES • Linked list of messages • Message queue table in kernel address space • Identified by message queue identifier
  • 3. KERNEL DATA STRUCTURE •A name which Struct msqid_dsis anA MessageKey integer ID Queue {•A creator user ID and group ID •Assigned owner user ID and group ID struct ipc_perm msg_perm; •Read-write access permission msgqnum_t msg_qnum; of the queue for owners, msglen_t msg_qbytes; Message Record others group members and pid_t msg_lspid; •Last read time and process ID pid_t msg_lrpid; •Last write time and process ID time_t msg_stime •Pointer to a linked list of message time_t msg_rtime records. time_t msg_ctime Message Table : : }
  • 4. Kernel Handling Message Queue Sender Process •Message type •No of bytes of message Receiver Message Table •Pointer to Process actual message data Actual Message
  • 5. SYSTEM-IMPOSED LIMITS <sys/msg.h> SYSTEM LIMIT Meaning MSGMNI The maximum number of message queue that may exists at any given time in a system MSGMAX The maximum number of bytes of data allowed for a message MSGMNB The maximum number of bytes of all messages allowed in a queue MSGTQL The maximum number of messages in all queues allowed in a system
  • 6. APIs FOR MESSAGE MANIPULATION #include <sys/types.h> #include <sys/ipc.h> #include <sys/message.h> MESSAGE API USES msgget Open and create if needed, a message queue for access msgsnd Sends a message to message queue msgrcv Receives a message from message queue msgctl Manipulate the control data of a message queue
  • 7. MSGGET • Prototype #include <sys/types.h> #include <sys/ipc.h> #include <sys/message.h> int msgget (key_t key, int flag); Returns -1 when fails • Opens a message queue with ID as key • If the key value is a manifested constant IPC_PRIVATE the API allocates a special message queue to be used exclusively by the calling process. – Flag can take two values: • 0: API aborts if there is no message queue whose key ID matches the given key value otherwise return a descriptor for that queue. • IPC_CREAT: Creates a new queue (if none exists) with given key ID and read-write access permission. – Ex: int msgfdesc = msgget(15, IPC_CREAT|0644); » IPC_EXCL ensures the API succeeds only if it creates a new msg queue.
  • 8. MSGSND • Prototype is a pointer to an object that contains the actual message msgPtr: it text and #include <sys/types.h> be sent and message type to #include <sys/ipc.h> #include <sys/message.h> int msgsnd (int msgfd, const void* msgPtr, int len, int flag); struct msgbuf Returns -1 when fails 0 on success { • Send a message pointed by msgPtr to a message long mtype queue designated message type // by the msgfd descriptor char mtext[MSGMAX] • The len value is the sizehold bytes of the message // buffer to in the message text } • Two values of flag: – 0: Process is blocked if needed until the process call is completed. – IPC_NOWAIT: Function abort if the process is to be blocked ----- (EAGAIN)
  • 9. MSGRCV • Prototype #include <sys/types.h> #include <sys/ipc.h> #include <sys/message.h> If there is message in queuemsgfd, const void* msgPtr, criteria but mtype, int flag); the int msgrcv (int that satisfies the selection int len, int is larger than len, Success: Returns number of bytes written function returns a failure status • Receive a message of type mtype from a message queue If MSG_NOERROR is set in the flag value, a message-1 queue is selectable Fail: Returns in the designated by the msgfd descriptor in an object pointed by the msgPtr irrespective of length. • The len value is the max size in bytes of the message that can be received • Two values of flag: – 0: Process is blocked if no message in queue matched the selection criteria specified by mtype – IPC_NOWAIT: The call is non blocking (returns -1 with errno set to ENOMSG)
  • 10. mtype Values (type of the message to be received) mtype values Meaning 0 Receive the oldest message of any type in the queue Positive integer Receive the oldest message of specified message type Negative integer Receive a message whose message type is less than or equal to the absolute value of mytpe. If more than 1 receive the oldest and the smallest.
  • 11. MSGCTL • Prototype #include <sys/types.h> #include <sys/ipc.h> #include <sys/message.h> int msgctl (int msgfd, int cmd, struct msqid_ds* mbufPtr); Fail: returns -1 • Used to query the control data of a message queue designated by the msgfd:argument 0 Success returns • To change the information within the control data of the queue • To remove a message queue
  • 12. cmd Values cmd value Meaning IPC_STAT Copy control data of the queue to the object pointed by the mbufPtr IPC_SET Change the control data of the queue by those specified in the object pointed by mbufPtr IPC_RMID Remove the queue from the system Note: The calling process for IPC_SET and IPC_RMID must be superuser, creator or the assigned owner of the queue.
  • 14. THANK YOU • Queries ? – Just Google it 