Linux命令 lctl,unix高级编程及unix网络编程(进程通信)编译方法

#include    "unpipc.h"

#define MAX_DATA    64*1024

#define MAX_NMESG   4096

#define MAX_NIDS    4096

int     max_mesg;

struct mymesg {

long  type;

char  data[MAX_DATA];

} mesg;

int

main(int argc, char **argv)

{

int     i, j, msqid, qid[MAX_NIDS];

/* 4first try and determine maximum amount of data we can send */

//  msqid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT);

msqid = Msgget(IPC_PRIVATE, IPC_CREAT|0660);

mesg.type = 1;

for (i = MAX_DATA; i > 0; i -= 128) {

if (msgsnd(msqid, &mesg, i, 0) == 0) {

printf("maximum amount of data per message = %d\n", i);

max_mesg = i;

break;

}

if (errno != EINVAL)

err_sys("msgsnd error for length %d", i);

}

if (i == 0)

err_quit("i == 0");

Msgctl(msqid, IPC_RMID, NULL);

/* 4see how many messages of varying size can be put onto a queue */

mesg.type = 1;

for (i = 8; i <= max_mesg; i *= 2) {

//  msqid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT);

msqid = Msgget(IPC_PRIVATE, IPC_CREAT|0660);

for (j = 0; j 

if (msgsnd(msqid, &mesg, i, IPC_NOWAIT) != 0) {

if (errno == EAGAIN)

break;

err_sys("msgsnd error, i = %d, j = %d", i, j);

break;

}

}

printf("%d %d-byte messages were placed onto queue,", j, i);

printf(" %d bytes total\n", i*j);

Msgctl(msqid, IPC_RMID, NULL);

}

/* 4see how many identifiers we can "open" */

mesg.type = 1;

for (i = 0; i <= MAX_NIDS; i++) {

//if ( (qid[i] = msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT)) == -1) {

if ( (qid[i] = msgget(IPC_PRIVATE, IPC_CREAT|0660)) == -1) {

printf("%d identifiers open at once\n", i);

break;

}

}

for (j = 0; j 

Msgctl(qid[j], IPC_RMID, NULL);

exit(0);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值