Quantcast
Channel: Java Question Bank » Cpp Programs
Viewing all articles
Browse latest Browse all 22

‘C’ program to create a message queue with read and write permissions to write 3 messages to it with different priority numbers.

$
0
0

**************************************************************************************************************************************************

Program:To write a c program to create a message queue with read and write permissions to write 3 messages to it with different priority numbers.

**************************************************************************************************************************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//receiver.c
1 #include<stdio.h>
2 #include<sys/msg.h>
3 #include<sys/ipc.h>
4  main()
5  {
6          int msqid,t;
7          int key,r;
8          struct mymsg
9          {
10                 long type;
11                 char mtext[512];
12          }msg;
13          key=ftok("arth.sh",78);
14          printf("Enter the type of the message :\n");
15          scanf("%ld",&msg.type);
16          msqid=msgget(key,IPC_CREAT|0666);
17          r=msgrcv(msqid,&msg,sizeof(msg),msg.type,IPC_NOWAIT);
18          if(r==-1)
19          {
20                  printf("Message received failed\n");
21          }
22          else
23          {
24                  printf("Message received successively\n");
25                  printf("Message = %s",msg.mtext);
26          }
27  }
~

/*-------------------------------------INPUT/OUTPUT--------------------------
-bash-3.2$ cc receiver_msgqq.c
-bash-3.2$ ./a.out
Enter the type of the message :
hello
Message received successively



-bash-3.2$ ipcs

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x070006ed 0          09121f0007 666        0            0
0x640011f2 32769      09121f0007 666        0            0
0xf40011f2 65538      09121f0007 666        1560         3
0x0e001c23 98307      09121f0004 666        336          3
0x070011f2 131076     09121f0007 666        0            0
0x09001a8e 163845     09121f0009 666        0            0
0x090008f2 196614     09121f0009 666        0            0
0x00000100 229383     09121f0044 666        3640         7
0x4e000410 262152     09121f0078 666        1040         2


-------------------------------------------------------------------------*/

324 total views, 3 views today


Viewing all articles
Browse latest Browse all 22

Trending Articles