Advertisement
Guest User

serv.c

a guest
May 29th, 2013
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/msg.h>
  5. #include <stdlib.h>
  6. typedef struct our_msgbuf{
  7. long mtype;
  8. char buffer[80];
  9. } Message;
  10.  
  11. int main(){
  12. Message msg;
  13. int msgid,key,n;
  14. if(key=ftok("serv",'A') <0){
  15. perror("ftok");
  16. printf("Can't obtaint key\n");
  17. exit(1);
  18. }
  19. msg.mtype=1L;
  20. if(msgid=msgget(key,0666|IPC_CREAT)<0){
  21. perror("msgget");
  22. printf("Can't create IPC\n");
  23. exit(1);
  24. }
  25. printf("%d\n",msgid);
  26. n=msgrcv(msgid,&msg,sizeof(msg),msg.mtype,0);
  27. if(n>0){
  28. if(write(1,msg.buffer,n)!=n){
  29. printf("Error of output\n");
  30. exit(1);
  31. }
  32. }
  33. else{
  34. printf("Error while reading the message\n");
  35. perror("read");
  36. }
  37. exit(0);
  38. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement