Sponsored Content
Full Discussion: C Posix - msgsnd() msgrcv
Top Forums Programming C Posix - msgsnd() msgrcv Post 302285165 by Corona688 on Saturday 7th of February 2009 01:41:30 PM
Old 02-07-2009
Compiling your receiver program generated these warnings on my platform:
Code:
msgrcv.c: In function 'main':
msgrcv.c:17: warning: cast from pointer to integer of different size
msgrcv.c:18: warning: cast from pointer to integer of different size
msgrcv.c:36: warning: incompatible implicit declaration of built-in function 'exit'

These warnings are nothing to sneeze at. The first two in particular are for these lines:

Code:
 msgp.temp=(int) argv[1];
 msgp.pid=(int) argv[2];

This does not do what you think they do! Adding the line
Code:
printf("msgp.temp=%d msgp.pid=%d\n", msgp.temp, msgp.pid);

shows
Code:
msgp.temp=-521312457 msgp.pid=-521312455

Operators in C can't convert anything except atomic types, which strings aren't; as far as C's concerned strings are just arrays and pointers. What you're getting is the memory address the string is stored in. It may not have generated a warning for your platform, if pointers and integers are the same size on it(i.e. 32-bit. I'm running 64-bit.)

You need to use a library function to convert them from strings. A quick-and-dirty fix would be to use atoi(argv[1]) and atoi(argv[2]) instead. These need you to include stdlib.h.

The last warning says the function exit() has no prototype, because it needs stdlib.h too. Best not to ignore those warnings since they can cause crashes in some circumstances.
 

10 More Discussions You Might Find Interesting

1. Programming

msgrcv pending forever !!!

When I am using msgrcv to get a message from a queue, in case of msgsnd some error, the msgrcv thread will waiting forever. Is there some way that I can specify a time out value for this queue ? just let msgrcv wait for some time, if no message comes during this time slot, msgrcv just return... (3 Replies)
Discussion started by: Yun Gang Chen
3 Replies

2. UNIX for Dummies Questions & Answers

msgrcv : Invalid argument

Hi All, Please guide me how to get rid : msgrcv : Invalid argument. I am using message queues: msgsnd and msgrcv, I am able to send through msgsnd and receive through msgrcv, but at times i get the belo error. msgrcv : Invalid argument. (1 Reply)
Discussion started by: answers
1 Replies

3. AIX

msgrcv crash in AIX 5.3 SP6

Hi All, I have a piece of code like blow. It is working fine with AIX 5.3 SP3. When the same thing is getting executed in AIX 5. SP6 it is giving segmentation fault. If I put debug statements before and after, it works fine. rc = msgrcv(mqid, &msg, size, HIGH_PRIORITY_FIRST , 0) ... (0 Replies)
Discussion started by: sandhya_chp
0 Replies

4. Programming

Posix

HI, When i am configuring php in SUN Solaris. I am getting the below error. configure: error: Your system seems to lack POSIX threads. Do i need to install POSIX? If so can somebody let me know where can i download POSIX for Solaris 8? Thanks, (2 Replies)
Discussion started by: Krrishv
2 Replies

5. UNIX for Advanced & Expert Users

Posix threads

Hi, consider the code below: #include <stdio.h> . . struct myStruct { char *message ; int id; }; . . . void *thread_function( void *ptr ); nt main() { pthread_t thread1, thread2 ,thread3 ; struct myStruct nico1; (2 Replies)
Discussion started by: Behnaz
2 Replies

6. What is on Your Mind?

Linux posix

Hi everybody, i couldn't think of any better place to ask this question. Does LINUX totally confirm with ALL of the POSIX standards??. If not which areas does it diverge?? my apologies if this questions seems sooo stupid to some of you.. thanks (0 Replies)
Discussion started by: abhiram7
0 Replies

7. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: daredevil82m
1 Replies

8. UNIX for Advanced & Expert Users

System V or POSIX

Hi , I am using UNIX network programming Vol1 (by R Stevens) book to learn about IPC. I would be using HP-UX,Solaris and Linux at my work. I have sections for POSIX and for System V in that book. I am quite confused in indentifying those OSs as POSIX or SYstem V. Can anyone please... (1 Reply)
Discussion started by: kumaran_5555
1 Replies

9. Programming

POSIX Thread Help

I want to create a program that creates 2 child process, and each of them creates 2 threads, and each thread prints its thread id. I0ve allread done that the outuput isn't the outuput i want. When a run the following comand "$./a.out | sort -u | wc -l" I have the folowing output 2 $: It should... (3 Replies)
Discussion started by: pharaoh
3 Replies

10. Programming

Message queue is not blocked in msgsnd

Hi, I am trying to send/receive data by message queue and expecting it to be blocked on send/read for other side (at least this is my understooding ) , I am connecting message between perl<->C , perl is working as expected , but in C msgsnd and msgrcv are not waiting (blocked) untill second side... (6 Replies)
Discussion started by: alexse
6 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 02:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy