Advertisement
Guest User

clnt.c

a guest
May 29th, 2013
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/ipc.h>
  5. #include <sys/msg.h>
  6. #include <stdlib.h>
  7. #include <errno.h>
  8. typedef struct our_msgbuf{
  9. long mtype;
  10. char buffer[80];
  11. } Message;
  12.  
  13. int main(){
  14. Message msg;
  15. int msgid,key,n,length;
  16. if(key=ftok("serv",'A') <0){
  17.  
  18.  
  19. printf("Can't obtaint key\n");
  20. exit(1);
  21. }
  22. msg.mtype=1L;
  23. if(msgid=msgget(key,0)<0){
  24. printf("Can't access to IPC\n");
  25. exit(1);
  26. }
  27. if((length=sprintf(msg.buffer,"Hello world\n")<0)){
  28.  
  29. printf("Error while copying\n");
  30. exit(1);
  31. }
  32. if(msgsnd(msgid,(void*)&msg,length,0)!=0){
  33. perror("send");
  34. printf("Error while sending the message\n");
  35. exit(1);
  36. }
  37. if(msgctl(msgid,IPC_RMID,0)<0){
  38. printf("Error while deleting queue\n");
  39. exit(1);
  40. }
  41. exit(0);
  42. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement