| | |
Message Queue Error
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 60
Reputation:
Solved Threads: 1
I am new to message queues and IPC in general. I am trying to have a process establish the queue and send a message. Then I fork and the child will read the message. The goal is to measure the execution time for different sized messages.
The msgsnd is returning a -1 and I have no idea as to why its not sending anything. Any help is appreciated. Thanks in advance
Output
The msgsnd is returning a -1 and I have no idea as to why its not sending anything. Any help is appreciated. Thanks in advance
C Syntax (Toggle Plain Text)
int main() { //establish the character array to be passed around int msgSize = 1024; char charArray[msgSize]; clock_t timeStampBegin; clock_t timeStampEnd; key_t key = 1234; /* key to be passed to msgget() */ int msqid; /* return value from msgget() */ //establish the message queue and make sure that it properly established if ((msqid = msgget(key, IPC_CREAT)) == 1) { perror("msgget: msgget failed"); //exit(1); } else { (void) fprintf(stderr, "msgget succeeded\n"); } //Take an initial timestamp timeStampBegin = clock(); //printf("\nTimeStampBegin = %d\n", timeStampBegin); //int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) int amountSent = msgsnd(1234, &charArray, msgSize, 0); printf("%d bytes were sent", amountSent); if(fork() == 0) { //this is the child, this is the one that we want to recieve the info. char recievedArray[100000]; if((size_t)msgSize == msgrcv(1234, &recievedArray, msgSize, 0, 0)) printf("Mesage was recieved"); timeStampEnd = clock(); //printf("Time for transit of size %d = %f", msgSize, (double)(timeStampEnd-timeStampBegin)); } printf("\n"); return 0; }
Output
C Syntax (Toggle Plain Text)
msgget succeeded -1 bytes were sent -1 bytes were sent
![]() |
Similar Threads
- POSIX message queue error in mq_receive() (C)
- windows live 2009 error message 'send error' (Viruses, Spyware and other Nasties)
- POSIX Message Queue (C++)
- Looking for open source message queue implementation (Java)
- system call to read the windows kernel message queue (C++)
- Need help!! Error message :Parse error T_String... (PHP)
Other Threads in the C Forum
- Previous Thread: Merge sort or an alternative..
- Next Thread: non preemptive scheduler
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter changingto char character cm convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o inches intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h windowsapi





