Processes can exchange messages using Message Queues. Sending process message is saved in a queue, Receiving process reads the message from queue.
Below program sends message to queue.
Below snapshot is the code for receiving process which reads message from queue.
#gcc msg_snd.c -o msg_snd
#gcc msg_recv.c -o msg_recv
1. Include headers
2. msgq_id (message id) is an arbitrary number of type int generated by msgget() which should be passed as parameter/argument to msgsnd(), msgrcv()
msgq_id can also be generated using ftok()
3. key (key_t is of type int) is another arbitrary number. Same key value must be passed as parameter/argument to msgsnd() and msgrcv().
4. Message Type (mtype) is another arbitrary number. Same mtype should be passed as parameter/argument to msgsnd(), msgrcv()
5. mtype is passed as struct mbuf argument to msgsnd(), and long type to msgrcv()
6. for man page of any API run man command e.g.
man 2 msgsnd
This is pretty high-level overview of Message Queues.
Feel free to drop a comment.
Other articles on C languagehttp://darshanams.blogspot.in/2011/09/building-single-binary-from-multiple-c.html
Post a Comment