Visit Our UNIX and Linux User Community


IPC Message Queue. msgrcv doesnt work..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers IPC Message Queue. msgrcv doesnt work..
# 1  
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);
}
# 2  
Old 01-10-2010
Please no not post homework in the main Forums. Thread closed.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #167
Difficulty: Easy
The Transmission Control Protocol (TCP) is one of the least used protocols of the Internet protocol suite.
True or False?

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Programming

IPC - queue problems

Hi, Im 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

6. 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

7. 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

8. 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

9. 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

10. 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

Featured Tech Videos