-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path025.c
More file actions
79 lines (67 loc) · 2.79 KB
/
025.c
File metadata and controls
79 lines (67 loc) · 2.79 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
..........................................................................................................................................
Name : 025.c
Author : SHRUTI VERMA
Description :Write a program to print a message queue's (use msqid_ds and ipc_perm structures)
a. access permission
b. uid, gid
c. time of last message sent and received
d. time of last change in the message queue
d. size of the queue
f. number of messages in the queue
g. maximum number of bytes allowed
h. pid of the msgsnd and msgrcv
Date : 18 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/msg.h>
#include<sys/ipc.h>
#include<sys/syscall.h>
#include<time.h>
int main() {
struct msqid_ds msg;
int key, msgid;
key = ftok("file.txt", 'a');
msgid = msgget(key, IPC_CREAT|0744);
msgctl(msgid, IPC_STAT, &msg);
printf("Details of message queue through msqid_ds: \n");
printf("Access permissions : %o\n", msg.msg_perm.mode);
printf("UID : %d\n", msg.msg_perm.uid);
printf("GID : %d\n", msg.msg_perm.gid);
printf("Time of last message sent : %s", ctime(&msg.msg_stime));
printf("Time of last message received : %s", ctime(&msg.msg_rtime));
printf("Time of last change in the message queue : %s", ctime(&msg.msg_ctime));
printf("Size of the queue : %lu\n", msg.msg_cbytes);
printf("Number of messages in the queue : %lu\n", msg.msg_qnum);
printf("Maximum number of bytes allowed : %lu\n", msg.msg_qbytes);
printf("PID of msgsnd : %d\n", msg.msg_lspid);
printf("PID of msgrcv : %d\n", msg.msg_lrpid);
struct ipc_perm perm = msg.msg_perm;
printf("\nDetails of message queue through ipc_perm: \n");
printf("Access permissions : %o\n", perm.mode);
printf("UID : %d\n", perm.uid);
printf("GID : %d\n", perm.gid);
}
/*-----------------------------------------OUTPUT-----------------------------------------------
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ gcc 025.c -o 025.out
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./025.out
Details of message queue through msqid_ds:
Access permissions : 744
UID : 1000
GID : 1000
Time of last message sent : Thu Jan 1 05:30:00 1970
Time of last message received : Thu Jan 1 05:30:00 1970
Time of last change in the message queue : Thu Sep 18 13:42:19 2025
Size of the queue : 0
Number of messages in the queue : 0
Maximum number of bytes allowed : 16384
PID of msgsnd : 0
PID of msgrcv : 0
Details of message queue through ipc_perm:
Access permissions : 744
UID : 1000
GID : 1000
*/