fork download
  1. #include<sys/types.h>
  2. #include<sys/ipc.h>
  3. #include<sys/msg.h>
  4. #include<stdio.h>
  5. #include<string.h>
  6. #include<stdlib.h>
  7. struct message{
  8. long mtype;
  9. char mtext[15];
  10. };
  11. int main(){
  12. int msgid,len;
  13. key_t key;
  14. struct message msg;
  15. key=131;
  16. msgid = msgget(key,IPC_CREAT|0666);
  17. printf("\nq=%d",msgid);
  18. printf("Enter message:");
  19. scanf("%[^\n]",msg.mtext);
  20. msg.mtype=1;
  21. len=strlen(msg.mtext);
  22. if(msgsnd(msgid,&msg,len,0)==-1){
  23. printf("error\n");
  24. exit(1);
  25. }
  26. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
q=0Enter message: