Posix Message Queues Courtesy of W. Richard Stevens Unix Network Programming Volume 2: Interprocess Communication.

Slides:



Advertisements
Similar presentations
Florida State UniversityCOP5570 – Advanced Unix Programming IPC mechanisms Pipes Sockets System V IPC –Message Queues –Semaphores –Shared Memory.
Advertisements

Review: Name/Address conversion: –What does the domain name system do? –Which system calls use the domain name system? –How does it work? –How does getservbyname.
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Inter-Process Communication: Message Passing Tore Larsen Slides by T. Plagemann, Pål Halvorsen, Kai Li, and Andrew S. Tanenbaum.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
CS 311 – Lecture 09 Outline Introduction to Systems programming – System calls – Categories of system calls Error Management System calls File Handling.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Fork Fork is used to create a child process. Most network servers under Unix are written this way Concurrent server: parent accepts the connection, forks.
Standard C Library Application Programming Interface to System-Calls.
1 Advanced programming in UNIX 1 File I/O Hua LiSystems ProgrammingCS2690File I/O.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
NCHU System & Network Lab Lab 13 File I/O & Standard I/O.
Inter Process Communication. Introduction Traditionally describe mechanism for message passing between different processes that are running on some operating.
Unix IPC Unix has three major IPC constructs to facilitate interaction between processes: Message Queues (this PowerPoint document) permit exchange of.
T.B. Skaali, Department of Physics, University of Oslo) FYS 4220 – 2012 / #5 Real Time and Embedded Data Systems and Computing Message based Process-Process.
FreeRTOS.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
ECE 4110 – Internetwork Programming Client-Server Model.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Communication and Synchronization of concurrent tasks
Inter-Process Communication Mechanisms CSE331 Operating Systems Design.
C questions A great programmer codes excellent code in C and Java. The code does video decoding. Java code works faster then C on my computer. how come?
Operating Systems Recitation 1, March th, 2002.
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
Module 2 Programming with Processes. Processes Process -- a program in execution –May share code segments –Typically do not share data, stack, heap OS.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
Florida State UniversityCOP5570 – Advanced Unix Programming Today’s topics System V Interprocess communication (IPC) mechanisms –Message Queues –Semaphores.
Chapter 71 Deadlock Detection revisited. Chapter 72 Message Passing (see Section 4.5 in Processes Chapter)  A general method used for interprocess communication.
Queues, Pipes and Sockets. QUEUE A structure with a series of data elements with the first element waiting for an operation Used when an element is not.
Introduction to Socket
Week 12 - Wednesday.  What did we talk about last time?  File I/O  Binary trees  Lab 11.
IPC Programming. Process Model Processes can be organized into a parent-child hierarchy. Consider the following example code: /* */
Socket Programming Lab 1 1CS Computer Networks.
Operating Systems Yasir Kiani. 13-Sep Agenda for Today Review of previous lecture Interprocess communication (IPC) and process synchronization UNIX/Linux.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
Operating Systems Recitation 4, April th, 2002 Signals.
Chapter 7 Files By C. Shing ITEC Dept Radford University.
Interprocess Communication Anonymous Pipes Named Pipes (FIFOs) popen() / pclose()
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Pipes Pipes are an inter-process communication mechanism that allow two or more processes to send information to each other.
Interprocess Communication
 Wind River Systems, Inc Chapter - 7 Intertask Communication.
Named Pipes. Kinds of IPC u Mutexes/Conditional Variables/Semaphores u Pipes u Named pipes u Signals u Shared memory u Messages u Sockets.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
Signals & Message queue Inter process mechanism in Linux system 3/24/
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
January 7, 2003Serguei Mokhov, 1 File I/O System Calls Reference COMP 229, 444, 5201 Revision 1.2 Date: July 21, 2004.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Files in UNIX u UNIX deals with two different classes of files:  Special Files  Regular Files u Regular files are just ordinary data files on disk -
Principles of Operating Systems Lecture 14
Threads and Cooperation
Unix IPC Unix has three major IPC constructs to facilitate interaction between processes: Message Queues (this PowerPoint document) permit exchange of.
Socket Programming.
CSE 333 – Section 3 POSIX I/O Functions.
Unix programming Term: Unit-V I PPT Slides
CSE 333 – Section 3 POSIX I/O Functions.
CSE 333 – Section 3 POSIX I/O Functions.
Presentation transcript:

Posix Message Queues Courtesy of W. Richard Stevens Unix Network Programming Volume 2: Interprocess Communication

Introduction A message queue is a linked list of messages A message queue is a linked list of messages Threads can put messages into and remove messages from the queue Threads can put messages into and remove messages from the queue Each message is a record with a priority assigned by the sender Each message is a record with a priority assigned by the sender There is no requirement that someone be waiting for a message There is no requirement that someone be waiting for a message Message queues have kernel persistence Message queues have kernel persistence

Attributes An unsigned integer priority An unsigned integer priority The length of the data portion (possibly 0) The length of the data portion (possibly 0) The data itself The data itself These differ from pipes and FIFOs which are byte streams with no message boundaries and no type These differ from pipes and FIFOs which are byte streams with no message boundaries and no type The head of the queue contains two attributes: the maximum number of messages and the maximum message size The head of the queue contains two attributes: the maximum number of messages and the maximum message size

Functions Functions #include #include mqd_t mq_open(const char *name, int oflag, mode_t mode, struct mq_attr *attr); mqd_t mq_open(const char *name, int oflag, mode_t mode, struct mq_attr *attr); returns a message queue descriptor returns a message queue descriptor oflag is one of O_RDONLY, O_WRONLY, or O_RDWR and may be ORed with O_CREAT, O_EXCL, and O_NONBLOCK oflag is one of O_RDONLY, O_WRONLY, or O_RDWR and may be ORed with O_CREAT, O_EXCL, and O_NONBLOCK attributes specify size and number of messages attributes specify size and number of messages

Functions Functions mq_close(mqd_t mqdes); mq_close(mqd_t mqdes); int mq_unlink(const char *name); int mq_unlink(const char *name); removes the name from the system removes the name from the system

Functions (continued) int mq_getattr(mqd_t mqdes, struct mq_attr *attr); int mq_getattr(mqd_t mqdes, struct mq_attr *attr); int mq_setattr(mqd_t mqdes, const struct *attr, struct mq_attr *oattr); int mq_setattr(mqd_t mqdes, const struct *attr, struct mq_attr *oattr); int mq_send(mqd_t mqdes, const char *ptr, size_t len, unsigned int prio); int mq_send(mqd_t mqdes, const char *ptr, size_t len, unsigned int prio); ssize_t mq_receive(mqd_t mqdes, char *ptr, size_t len, unsigned int *priop); ssize_t mq_receive(mqd_t mqdes, char *ptr, size_t len, unsigned int *priop);

Functions (mq_notify) mq_notify(mqd_t mqdes, const struct sigevent *notification); mq_notify(mqd_t mqdes, const struct sigevent *notification); #include #include If the notification argument is nonnull, the process wants to be notified when a message arrives for an empty queue If the notification argument is nonnull, the process wants to be notified when a message arrives for an empty queue If the notification argument is null, the existing registration is removed If the notification argument is null, the existing registration is removed

mq_notify (continued) Only one process at a time can be registered for notification for a given queue Only one process at a time can be registered for notification for a given queue A thread blocked in mq_receive takes precedence over a process waiting for notification A thread blocked in mq_receive takes precedence over a process waiting for notification When the notification is sent, the registration is removed When the notification is sent, the registration is removed

Assignment 1 Modify pxmsg/mqnotifysig1.c so that it does not call mq_notify when the signal is delivered. Then send two messages to the queue and verify that the signal is not generated for the second message. Why not? Modify pxmsg/mqnotifysig1.c so that it does not call mq_notify when the signal is delivered. Then send two messages to the queue and verify that the signal is not generated for the second message. Why not?

Assignment 2 Modify the same program so that it does not read the message from the queue when the signal is delivered. Instead, just call mq_notify and print that the signal was received. Then send two messages to the queue and verify that the signal is not generated for the second message. Why not? Modify the same program so that it does not read the message from the queue when the signal is delivered. Instead, just call mq_notify and print that the signal was received. Then send two messages to the queue and verify that the signal is not generated for the second message. Why not?

Assignment 3 Modify mqcreate.c as follows: Modify mqcreate.c as follows: before calling mq_open, print a message and sleep for 30 seconds. before calling mq_open, print a message and sleep for 30 seconds. After mq_open returns, print another message, sleep for 30 seconds, and then call mq_close. After mq_open returns, print another message, sleep for 30 seconds, and then call mq_close. Run the program specifying a large number of messages (200,000) and a maximum size of 10 bytes. Run the program specifying a large number of messages (200,000) and a maximum size of 10 bytes. During the first 30 second pause run ps and look at the memory size of the program. Do this again after mq_open has returned. Can you explain what happens? During the first 30 second pause run ps and look at the memory size of the program. Do this again after mq_open has returned. Can you explain what happens?