Preview:
//Message Queue(senders)
#include <stdio.h> 
#include <sys/ipc.h> 
#include <sys/msg.h> 
  
// structure for message queue
struct mesg_buffer { 
    long mesg_type; 
    char mesg_text[100]; 
} message; 


int main() 
{ 
    key_t key; 
    int msgid;
    // ftok to generate unique key 
    key = ftok("somefile", 65); 
    msgid = msgget(key, 0666 | IPC_CREAT); 
    message.mesg_type = 1; 
    printf("Insert message : "); 
     fgets(message.mesg_text, sizeof(message.mesg_text), stdin);

    // msgsnd to send message 
    msgsnd(msgid, &message, sizeof(message), 0); 
    // display the message 
    printf("Message sent to sever is : %s \n", message.mesg_text);

    return 0; 
} 
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter