Sponsored Content
Top Forums UNIX for Dummies Questions & Answers IPC Message Queue. msgrcv doesnt work.. Post 302385846 by daredevil82m on Sunday 10th of January 2010 09:45:57 AM
Old 01-10-2010
Error IPC Message Queue. msgrcv doesnt work..

Hi everybody,

this is the situation. there is a programm XYZ which opens a message queue with the key 47110815 and waits for a SIGUSR1. After receiving this signal it sends a message with type 100 and a number (as ASCII) in the message-body.

I have to write a prog which frist sends the SIGUSR1 to that process XYZ and receives the message which XYZ loaded in the message queue. After that it has to send a message (with type = the number in the messagebody). After receiving my message XYZ will modify it and load it again in the message queue. I have to read that modified message again. I've written the code but it hangs up at the line where it should receive the message (msgrcv) for the first time.

executing XYZ will display its pid. we will start my prog with that pid as parameter and will use it to send SIGUSR1 to XYZ.

I cant view XYZ but can ensure that it works, cuz its from our proffessor.. It'd be great if onyone could help. Here is my code:

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#define KEY 47110815
#define MSIZE 100

struct message{
long type;
char data[MSIZE];
};

struct message m;

main(int i, char *p[]){
int id;
long number; char s[100];

kill(atoi(p[1]),10); //sends SIGUSR1 to process XYZ
printf("\nSIGUSR1 sent!\n");
id=msgget(KEY,0666 );

printf("Waiting for 1. Message from XYZ...\n");
msgrcv(id,&m,MSIZE,(long)100,0);
printf("Message received!\n");

number = m.type = (long) atoi(m.data);
strcpy(&m.data[0],"abcde");
msgsnd(id,&m,MSIZE,0);
printf("Message sent with Typ=%d Id=%d\n",m.type,id);

printf("Waiting for changed Message...\n");
sleep(0.5);
msgrcv(id,&m,MSIZE,(long)number,0);
printf("Changed Message received!:");
printf(">>%d>>%s\n",m.type,m.data);
}
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cd.. doesnt work

hi when i want to go to previous directory by typing cd.. i get the following message $ cd.. ksh: cd..: not found Please help rintingtong (2 Replies)
Discussion started by: rintingtong
2 Replies

2. HP-UX

ls command doesnt work

Good Day I mistakely renamed the dld.sl file in the /usr/lib directory. When i try to ls/ftp into the box i get this error :eek: crt0: ERROR couldn't open /usr/lib/dld.sl errno:000000002 I have tried to rename it back from the renamed file to the original file name, but it gives me the... (2 Replies)
Discussion started by: shawnbishop
2 Replies

3. HP-UX

posix ipc message queue

Hello, My question is related to "pipcs -qa" command under HP-UX 11i PA-RISC 64 bits. We have a little C program that creates posix ipc message queues using the mq_open() system function. The program fail with 'No space left on device' error when we create big queues. What is the system... (6 Replies)
Discussion started by: cadanir
6 Replies

4. UNIX for Dummies Questions & Answers

cp doesnt work - Help

When trying to copy a file in Solaris 8 it doesnt copy file or give a error. This worked 100% until the 29th. I've checked the rights and everything seems fine: drwxrwxrwx 2 bmuser bmgroup 11776 Jan 3 10:32 spool This is the file I want to copy: -rwxrwxrwx 1 bmuser bmgroup ... (26 Replies)
Discussion started by: rudi.okelly
26 Replies

5. Programming

How to limit max no of message in a posix message queue

Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
Discussion started by: mohit3884
0 Replies

6. Programming

IPC - queue problems

Hi, I´m having a lot of problems when working with message queues, both on HP-UX Systems and Sun Solaris. When we fill a queue with a messages, the system hangs and locks everything that relies on the use of IPC resources. Anyone knows how to eliminate this problem? Thanks, Haroldo Teixeira (2 Replies)
Discussion started by: haroldo
2 Replies

7. Shell Programming and Scripting

Email alert doesnt contain any message

I have created a script which will monitor disk space in unix, it will send an email alert that will notify the specified receipients. I used echo in the mailx command but the email doesnt contain any message. I have used printf to store the message ($message2) and when tried to display on the... (2 Replies)
Discussion started by: lscanaleta
2 Replies

8. Shell Programming and Scripting

loop doesnt work

It just does the break...even though the files are not the same... # Compare extracts #========================================== count=0 while (( count < 5 )) do (( count+=1 )) echo "Try $count" file1=$(ls -l /tmp/psjava.xml|... (5 Replies)
Discussion started by: sigh2010
5 Replies

9. AIX

Vi doesnt work

Hi Guys, I have a strange problem.( AIX 6.1) "vi" is not working at all..Whenever i #vi <anythin> ,, it returns the prompt back. Any clues folks?? (14 Replies)
Discussion started by: muzahed
14 Replies

10. UNIX for Dummies Questions & Answers

why doesnt it work?

I am trying to print out two fields in a file using awk. So, I have got awk -F '\t' 'NF = 2 {print $1 $2 "]"}' two.txt in a script called what.awk When i run this version like this - ./what.awk then it runs however I want to run the program like this awk -f what.awk two.txt. When I... (8 Replies)
Discussion started by: The undertaker
8 Replies
MSGSND(2)						      BSD System Calls Manual							 MSGSND(2)

NAME
msgsnd -- send a message to a message queue LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); DESCRIPTION
The msgsnd() function sends a message to the message queue specified in msqid. The msgp argument points to a structure containing the mes- sage. 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 (see msgrcv(2)), mtext is an array of msgsz bytes. The argument msgsz can range from 0 to a system-imposed maximum, MSGMAX. If the number of bytes already on the message queue plus msgsz is bigger than the maximum number of bytes on the message queue (msg_qbytes, see msgctl(2)), or the number of messages on all queues system-wide is already equal to the system limit, msgflg determines the action of msgsnd(). If msgflg has IPC_NOWAIT mask set in it, the call will return immediately. If msgflg does not have IPC_NOWAIT set in it, the call will block until: o The condition which caused the call to block does no longer exist. The message will be sent. o The message queue is removed, in which case -1 will be returned, and errno is set to EINVAL. o The caller catches a signal. The call returns with errno set to EINTR. After a successful call, the data structure associated with the message queue is updated in the following way: o msg_cbytes is incremented by the size of the message. o msg_qnum is incremented by 1. o msg_lspid is set to the pid of the calling process. o msg_stime is set to the current time. RETURN VALUES
The msgsnd() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The msgsnd() function will fail if: [EINVAL] The msqid argument is not a valid message queue identifier The message queue was removed while msgsnd() was waiting for a resource to become available in order to deliver the mes- sage. The msgsz argument is greater than msg_qbytes. The mtype argument is not greater than 0. [EACCES] The calling process does not have write access to the message queue. [EAGAIN] There was no space for this message either on the queue, or in the whole system, and IPC_NOWAIT was set in msgflg. [EFAULT] The msgp argument points to an invalid address. [EINTR] The system call was interrupted by the delivery of a signal. HISTORY
Message queues appeared in the first release of AT&T Unix System V. BUGS
NetBSD and FreeBSD do not define the EIDRM error value, which should be used in the case of a removed message queue. BSD
July 9, 2009 BSD
All times are GMT -4. The time now is 03:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy