Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <stdlib.h>
- #include <errno.h>
- typedef struct our_msgbuf{
- long mtype;
- char buffer[80];
- } Message;
- int main(){
- Message msg;
- int msgid,key,n,length;
- if(key=ftok("serv",'A') <0){
- printf("Can't obtaint key\n");
- exit(1);
- }
- msg.mtype=1L;
- if(msgid=msgget(key,0)<0){
- printf("Can't access to IPC\n");
- exit(1);
- }
- if((length=sprintf(msg.buffer,"Hello world\n")<0)){
- printf("Error while copying\n");
- exit(1);
- }
- if(msgsnd(msgid,(void*)&msg,length,0)!=0){
- perror("send");
- printf("Error while sending the message\n");
- exit(1);
- }
- if(msgctl(msgid,IPC_RMID,0)<0){
- printf("Error while deleting queue\n");
- exit(1);
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement