当前位置: 技术问答>linux和unix
why???
来源: 互联网 发布时间:2017-01-18
本文导语: #include #include #include #include #include void msg_stat(int , struct msgid_ds); main() { int gflags, sflags, rflags; key_t key; int msgid; int reval; struct msgsbuf { int mytype; char mtext[1]; }msg_sbuf; struct msgmbuf { int mytype; char mtext[10]; }msg_rbuf;...
#include
#include
#include
#include
#include
void msg_stat(int , struct msgid_ds);
main()
{
int gflags, sflags, rflags;
key_t key;
int msgid;
int reval;
struct msgsbuf
{
int mytype;
char mtext[1];
}msg_sbuf;
struct msgmbuf
{
int mytype;
char mtext[10];
}msg_rbuf;
struct msgid_ds msg_ginfo, msg_sinfo;
key = ftok("msg", 20);
gflags = IPC_CREAT|IPC_EXCL;
msgid = msgget(key, gflags|0666);
if(msgid == -1)
{
printf("msg create error");
return;
}
msg_stat(msgid, msg_ginfo);
sflags = IPC_NOWAIT;
msg_sbuf.mytype = 0;
msg_sbuf.mtext[0] = 'a';
reval = msgsnd(msgid, &msg_sbuf, sizeof(msg_sbuf.mtext), sflags);
if(reval == -1)
printf("msg send error");
msg_stat(msgid, msg_ginfo);
rflags = IPC_NOWAIT|MSG_NOERROR;
reval = msgrcv(msgid, &msg_rbuf, 4, 10, rflags);
if(reval == -1 )
printf("read msg error");
else
printf("read from msg queue %d bytes", reval);
msg_stat(msgid, msg_ginfo);
msg_sinfo.msg_perm.gid = 8;
msg_sinfo.msh_perm.uid = 8;
msg_sinfo.msg_qbytes = 16388;
reval = msgctl(msgid, IPC_SET, &msg_sinfo);
if(reval == -1)
{
printf("msg set error");
return;
}
msg_stat(msgid, msg_ginfo);
reval = msgctl(msgid, IPC_RMID, NULL);
if(reval == -1)
{
printf("unlink queue error");
return;
}
}
void msg_stat(int msgid, struct msgid_ds msg_info)
{
int reval;
sleep(1);
reval = msgctl(msgid, IPC_STAT, &msg_info);
if(reval == -1)
{
printf("get msg info error");
return;
}
printf("n");
printf("current number of bytes on queue is %d n", msg_info.msg_cbytes);
printf("number of message in queue is %d n", msg_info.msg_qnum);
printf("max number of bytes is %dn", msg_info.msg_qbytes);
printf("pid of last msgsnd is %dn", msg_info.msg_lspid);
printf("pid of last msgrvc is %dn", msg_info.msg_lrpid);
printf("last msgsnd time is %sn", ctime(&msg_info.msg_stime));
printf("last megrcv time is %sn", ctime(&msg_info.msg_rtime));
printf("last change time is %sn", ctime(&msg_info.msg_ctime));
printf("msg uid is %dn", msg_info.msg_perm.uid);
printf("msg gid is %dn", msg_info.mgs_perm.pid);
}
error:
msgtext.c:7:28: warning: ‘struct msgid_ds’ declared inside parameter list [enabled by default]
msgtext.c:7:28: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
msgtext.c: In function ‘main’:
msgtext.c:24:18: error: storage size of ‘msg_ginfo’ isn’t known
msgtext.c:24:29: error: storage size of ‘msg_sinfo’ isn’t known
msgtext.c:33:2: error: type of formal parameter 2 is incomplete
msgtext.c:40:2: error: type of formal parameter 2 is incomplete
msgtext.c:47:2: error: type of formal parameter 2 is incomplete
msgtext.c:57:2: error: type of formal parameter 2 is incomplete
msgtext.c: At top level:
msgtext.c:65:33: warning: ‘struct msgid_ds’ declared inside parameter list [enabled by default]
msgtext.c:65:42: error: parameter 2 (‘msg_info’) has incomplete type
|
编译错误来叨叨毛。
struct msqid_ds {
struct ipc_perm msg_perm; /* Ownership and permissions */
time_t msg_stime; /* Time of last msgsnd(2) */
time_t msg_rtime; /* Time of last msgrcv(2) */
time_t msg_ctime; /* Time of last change */
unsigned long __msg_cbytes; /* Current number of bytes in
queue (nonstandard) */
msgqnum_t msg_qnum; /* Current number of messages
in queue */
msglen_t msg_qbytes; /* Maximum number of bytes
allowed in queue */
pid_t msg_lspid; /* PID of last msgsnd(2) */
pid_t msg_lrpid; /* PID of last msgrcv(2) */
};
是q不是g
struct msqid_ds {
struct ipc_perm msg_perm; /* Ownership and permissions */
time_t msg_stime; /* Time of last msgsnd(2) */
time_t msg_rtime; /* Time of last msgrcv(2) */
time_t msg_ctime; /* Time of last change */
unsigned long __msg_cbytes; /* Current number of bytes in
queue (nonstandard) */
msgqnum_t msg_qnum; /* Current number of messages
in queue */
msglen_t msg_qbytes; /* Maximum number of bytes
allowed in queue */
pid_t msg_lspid; /* PID of last msgsnd(2) */
pid_t msg_lrpid; /* PID of last msgrcv(2) */
};
是q不是g
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。