SlideShare une entreprise Scribd logo
1  sur  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 

Contenu connexe

Tendances

Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
karan2190
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
shivli0769
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency control
AbDul ThaYyal
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
sumitjain2013
 

Tendances (20)

Parallel processing
Parallel processingParallel processing
Parallel processing
 
Cloud Infrastructure Mechanisms
Cloud Infrastructure MechanismsCloud Infrastructure Mechanisms
Cloud Infrastructure Mechanisms
 
Communication in Distributed Systems
Communication in Distributed SystemsCommunication in Distributed Systems
Communication in Distributed Systems
 
Cs8791 cloud computing introduction new
Cs8791  cloud computing introduction newCs8791  cloud computing introduction new
Cs8791 cloud computing introduction new
 
Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systems
 
Pram model
Pram modelPram model
Pram model
 
System models in distributed system
System models in distributed systemSystem models in distributed system
System models in distributed system
 
Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Dichotomy of parallel computing platforms
Dichotomy of parallel computing platformsDichotomy of parallel computing platforms
Dichotomy of parallel computing platforms
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency control
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternatives
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
Message passing ( in computer science)
Message   passing  ( in   computer  science)Message   passing  ( in   computer  science)
Message passing ( in computer science)
 
Computer architecture multi processor
Computer architecture multi processorComputer architecture multi processor
Computer architecture multi processor
 
Multithreaded processors ppt
Multithreaded processors pptMultithreaded processors ppt
Multithreaded processors ppt
 
Interprocess Communication
Interprocess CommunicationInterprocess Communication
Interprocess Communication
 

En vedette

unix interprocess communication
unix interprocess communicationunix interprocess communication
unix interprocess communication
guest4c9430
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKX
Mike Willbanks
 
Основы разработки требований по К.Вигерсу
Основы разработки требований по К.ВигерсуОсновы разработки требований по К.Вигерсу
Основы разработки требований по К.Вигерсу
Olya Kollen, PhD
 

En vedette (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
 

Similaire à Message queues

MPI Introduction
MPI IntroductionMPI Introduction
MPI Introduction
Rohit Banga
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
Mohd Tousif
 
Mote Mote Radio Communication
Mote Mote Radio CommunicationMote Mote Radio Communication
Mote Mote Radio Communication
Ankit Singh
 
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
jyoti9vssut
 

Similaire à 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
 

Dernier

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Dernier (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

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 