Sponsored Content
Full Discussion: Message queues
Top Forums Programming Message queues Post 71635 by blowtorch on Friday 13th of May 2005 12:27:48 AM
Old 05-13-2005
You would be best off having two programs, but not in the same way that you have created. Have one program that is the "server". This will create the message queue when it starts up, and destroy the queue when it shuts down. The second program will be the client program that will just connect to the message queue (no IPC_CREAT).

The client program will put messages with a type flag set to some unique value ( using the program's pid would be a good idea ); while msgrcv will be done with type set to the the unique value, but with the flag set to MSG_EXCEPT - this will pick up messages with any type that is not the value set as msgtyp in the msgrcv call.

A single program will probably complicate things unnecessarily.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

message queues

let 3 processes a, b and c are sharing msgs using msg queues.process 'a' sending msg to 'c' and in turn 'c' send sthat msg to 'b'.if something happens to c how can 'a' and 'b' know that 'c' is not available?????? (2 Replies)
Discussion started by: sukaam
2 Replies

2. Solaris

rogue message queues solaris 9

We have message queues created from our ERP system to our tax system via an application api written by the ERP software vendor. Occasionally when a user does not gracefully exit the ERP application, the message queue hangs. After a few months, this becomes a problem as the queues are all used... (2 Replies)
Discussion started by: MizzGail
2 Replies

3. Linux

maximun number of message queues

how to check the maximun number of message queues in current linux enviornment? is there any command ? (4 Replies)
Discussion started by: princelinux
4 Replies

4. Programming

shared memory and message queues

Hi, According to my understanding.. When message queues are used, when a process post a message in the queue and if another process reads it from the queue then the queue will be empty unlike shared memory where n number of processess can access the shared memory and still the contents remain... (2 Replies)
Discussion started by: rvan
2 Replies

5. UNIX for Advanced & Expert Users

UNIX Message Queues vs. Sockets

If I use sockets for IPC, and can easily distribute my applications. UNIX Message Queues are local to the processor. As I understand it, Message Queues still incur system call overhead, just like socket calls. What advantage does a UNIX Message Queue provide versus a TCP or UDP Socket,... (2 Replies)
Discussion started by: zen29sky
2 Replies

6. UNIX for Advanced & Expert Users

message queues

#include <sys/ipc.h> #include <sys/msg.h> int main() { int qid; int t; struct msgbuf mesg; qid=msgget(IPC_PRIVATE,IPC_CREAT); mesg.mtype=1L; mesg.mtext=1; t=msgsnd(qid,&mesg,1,0); printf("%d",t); } the program prints -1 as the result of msgsnd ,which means that msgsnd doesn't... (1 Reply)
Discussion started by: tolkki
1 Replies

7. UNIX for Dummies Questions & Answers

message queues

can any body provide a tutorial that explains the concept of message queues in UNIX in great detail (1 Reply)
Discussion started by: asalman.qazi
1 Replies

8. Programming

Persisting message queues to disk

Hi, I have searched the forums and could not find a relavant thread discussing my use case, hence the new post. Basically am trying to pass on work to dummy worker instances from controller which will pass on work to workers (client) To make use of host capacity, am planning to serialize... (2 Replies)
Discussion started by: matrixmadhan
2 Replies

9. Shell Programming and Scripting

Cleaning Message Queues

i have an application installed on AIX 5.3 and i have made a script that shutdown a proccesses that exceeded 10000kb of memory usage but i have a problem with cleaning the message queues of these proccesses after shutting them down. Is there any way to clean the message queues for this particular... (8 Replies)
Discussion started by: Portabello
8 Replies

10. UNIX for Advanced & Expert Users

Performance calculation for Message Queues

i have a program(C++ Code) that sends/receives information through queue's (Uses MQ) Is there any UNIX/LINUX tool that calculates the load and performance time for the same. If not how do i design the program that calculates the performance time. i know that time.h can be used but it gives... (2 Replies)
Discussion started by: vkca
2 Replies
MSGRCV(2)						      BSD System Calls Manual							 MSGRCV(2)

NAME
msgrcv -- receive a message from a message queue LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> int msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg); DESCRIPTION
The msgrcv() function receives a message from the message queue specified in msqid, and places it into the structure pointed to by msgp. This structure should consist of the following members: long mtype; /* message type */ char mtext[1]; /* body of message */ mtype is an integer greater than 0 that can be used for selecting messages, mtext is an array of bytes, with a size up to that of the system limit (MSGMAX). The value of msgtyp has one of the following meanings: o The msgtyp argument is greater than 0. The first message of type msgtyp will be received. o The msgtyp argument is equal to 0. The first message on the queue will be received. o The msgtyp argument is less than 0. The first message of the lowest message type that is less than or equal to the absolute value of msgtyp will be received. The msgsz argument specifies the maximum length of the requested message. If the received message has a length greater than msgsz it will be silently truncated if the MSG_NOERROR flag is set in msgflg, otherwise an error will be returned. If no matching message is present on the message queue specified by msqid, the behavior of msgrcv() depends on whether the IPC_NOWAIT flag is set in msgflg or not. If IPC_NOWAIT is set, msgrcv() will immediately return a value of -1, and set errno to ENOMSG. If IPC_NOWAIT is not set, the calling process will be blocked until: o A message of the requested type becomes available on the message queue. o The message queue is removed, in which case -1 will be returned, and errno set to EINVAL. o A signal is received and caught. -1 is returned, and errno set to EINTR. If a message is successfully received, the data structure associated with msqid is updated as follows: o msg_cbytes is decremented by the size of the message. o msg_lrpid is set to the pid of the caller. o msg_lrtime is set to the current time. o msg_qnum is decremented by 1. RETURN VALUES
Upon successful completion, msgrcv() returns the number of bytes received into the mtext field of the structure pointed to by msgp. Other- wise, -1 is returned, and errno set to indicate the error. ERRORS
The msgrcv() function will fail if: [EINVAL] The msqid argument is not a valid message queue identifier. The message queue was removed while msgrcv() was waiting for a message of the requested type to become available on it. The msgsz argument is less than 0. [E2BIG] A matching message was received, but its size was greater than msgsz and the MSG_NOERROR flag was not set in msgflg. [EACCES] The calling process does not have read access to the message queue. [EFAULT] The msgp argument points to an invalid address. [EINTR] The system call was interrupted by the delivery of a signal. [ENOMSG] There is no message of the requested type available on the message queue, and IPC_NOWAIT is set in msgflg. SEE ALSO
msgctl(2), msgget(2), msgsnd(2) HISTORY
Message queues appeared in the first release of AT&T System V UNIX. BSD
July 9, 2009 BSD
All times are GMT -4. The time now is 04:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy