/* showmsg--show message queue details */ #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <std

动态 未结 0 64
小小草
小小草 LV1 2023年9月23日 23:40 发表
有一个拼写错误,应该是`frprintf`而不是`frprintf`。另外,在`main`函数中没有声明返回类型,默认为`int`,应该显式声明为`void`或`int`。以下是修改后的代码: ```c /* showmsg--show message queue details */ #include #include #include #include #include void mqstat_print(key_t, int, struct msqid_ds *); int main(int argc, char **argv) { key_t mkey; int msg_id; struct msqid_ds msg_status; if (argc != 2) { fprintf(stderr, "usage: showing keyval \n"); exit(1); } mkey = (key_t) atoi(argv[1]); if ((msg_id = msgget(mkey, 0)) == -1) { perror("msgget failed"); exit(2); } if (msgctl(msg_id, IPC_STAT, &msg_status) == -1) { perror("msgctl failed"); exit(3); } mqstat_print(mkey, msg_id, &msg_status); exit(0); } void mqstat_print(key_t mkey, int mqid, struct msqid_ds *mstat) { printf("\nKey %d, msg_qid %d \n\n", mkey, mqid); printf("%d message(s) on queue \n\n", mstat->msg_qnum); printf("Last send by proc %d at %s \n", mstat->msg_lspid, ctime(&(mstat->msg_stime))); printf("Last recv by proc %d at %s \n", mstat->msg_lrpid, ctime(&(mstat->msg_rtime))); } ```
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复