| | |
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 |
#include * adobe ansi array arrays asterisks binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux locate looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi





