How it works...

We will start by generating an IPC key by invoking the ftok function. The filename and ID are supplied while creating the IPC key are messagefile and a, respectively. The generated key is assigned to the key variable. Thereafter, we will invoke the msgget function to create a new message queue. The message queue is associated with the IPC key we just created using the ftok function.

Next, we will define a structure by the name of msgstruc with two members, mtype and mesg. The mtype member helps in determining the sequence number of the message that is going to be sent or received from the message queue. The mesg member contains the message that is going to be read or written into the message queue. We will define a variable called msgbuf of the msgstruc structure type. The value of the mtype member is set to 1.

You will be prompted to enter the message that is going to be added to the message queue. The string you enter is assigned to the mesg member of the msgbuf structure. The msgsnd function is invoked to send the message you entered into the message queue. Once the message is written into the message queue, a text message is displayed on the screen as confirmation.

Now, let's move on to the other part of this recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset