LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 479|回复: 1

看下这个程序

[复制链接]
发表于 2005-2-24 21:03:32 | 显示全部楼层 |阅读模式

  1. #include<stdio.h>
  2. #include<sys/types.h>
  3. #include<sys/ipc.h>
  4. #include"err_exit.h"

  5. int main(void)
  6. {
  7.         key_t key,msgflg;
  8.         int perm_flags,flags;
  9.         int msqid;
  10.         printf("enter the disired key in hex= ");
  11.         scanf("%x",&key);
  12.         printf("\nenter the operation permiddipns in octal=");
  13.         printf("\nenter corresponding number to set the disired flags:\n");
  14.         printf("no flags   =0\n");
  15.         printf("IPC_CREAT     =1\n");
  16.         printf("IPC_EXCL         =2\n");
  17.         printf("IPC_CREAT and IPC_EXCL=  3\n");
  18.         printf("flags=");
  19.         printf("%d",&flags);
  20.         printf("\nkey=0x%x,perm_flags=0%o,flags=0%o\n",key,perm_flags,flags);
  21.         switch (flags){

  22.         case  0:
  23.                 msgflg=(perm_flags | 0);
  24.                 break;
  25.         case  1:
  26.                 msgflg=(perm_flags | 0);
  27.                 break;
  28.         case 2:
  29.                 msgflg=(perm_flags | 0);
  30.                 break;
  31.     case 3:
  32.                 msgflg=(perm_flags | 0);
  33.         }
  34.     printf("\nmsgget :calling msgget(% # 1x,% # o)\n",key,msgflg);
  35.     if((msqid=msgget(key,msgflg))==-1)
  36.           err_exit("the msgget failed");
  37.     else{
  38.            printf("the msgget succeeded :msqid= %d\n",msqid);
  39.            exit(0);
  40.     }
  41. }
复制代码


一个创建消息队列的程序,但我是只能输入1次为什么呢!?
 楼主| 发表于 2005-2-24 21:04:44 | 显示全部楼层
我执行结果如下


debian:/home# ./11-11
enter the disired key in hex= 0      /*输入后程序直接执行完毕*/

enter the operation permiddipns in octal=
enter corresponding number to set the disired flags:
no flags   =0
IPC_CREAT     =1
IPC_EXCL         =2
IPC_CREAT and IPC_EXCL=  3
flags=-1073743592
key=0x0,perm_flags=010005236140,flags=00

msgget :calling msgget(0,010005236140)
the msgget succeeded :msqid= 65538
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表