Exemplo n.º 1
0
int
main(int argc, char **argv)
{
	int		readid, writeid;

	readid = Msgget(MQ_KEY1, SVMSG_MODE | IPC_CREAT);
	writeid = Msgget(MQ_KEY2, SVMSG_MODE | IPC_CREAT);

	server(readid, writeid);

	exit(0);
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
	int		c, flag, mqid;
	long	type;
	ssize_t	n;
	struct msgbuf	*buff;

	type = flag = 0;
	while ( (c = Getopt(argc, argv, "nt:")) != -1) {
		switch (c) {
		case 'n':
			flag |= IPC_NOWAIT;
			break;

		case 't':
			type = atol(optarg);
			break;
		}
	}
	if (optind != argc - 1)
		err_quit("usage: msgrcv [ -n ] [ -t type ] <pathname>");

	mqid = Msgget(Ftok(argv[optind], 0), MSG_R);

	buff = Malloc(MAXMSG);

	n = Msgrcv(mqid, buff, MAXMSG, type, flag);
	printf("read %d bytes, type = %ld\n", n, buff->mtype);

	exit(0);
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	int msqid;
	msqid = Msgget(MQ_KEY1, SVMSG_MODE | IPC_CREAT);
	server(msqid, msqid);
	exit(0);
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	int msqid;
	msqid = Msgget(MQ_KEY1, 0);
	client(msqid, msqid);
	exit(0);
}
int
main(int argc, char **argv)
{
	int				msqid;
	struct msqid_ds	info;
	struct msgbuf	buf;

	msqid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT);

	buf.mtype = 1;
	buf.mtext[0] = 1;
	Msgsnd(msqid, &buf, 1, 0);

	Msgctl(msqid, IPC_STAT, &info);
	printf("read-write: %03o, cbytes = %lu, qnum = %lu, qbytes = %lu\n",
		   info.msg_perm.mode & 0777, (unsigned long int) info.msg_cbytes,
		   (unsigned long int ) info.msg_qnum, (unsigned long int) info.msg_qbytes);

	int ret = system("ipcs -q");
    if( ret == -1){
        perror("system\n");
        printf("Error in system call\n");
    }

	Msgctl(msqid, IPC_RMID, NULL);
	exit(0);
}
Exemplo n.º 6
0
int
main(int argc, char **argv)
{
	int		i, nloop, contpipe[2], msqid;
	pid_t	childpid;

	if (argc != 4)
		err_quit("usage: bw_svmsg <#loops> <#mbytes> <#bytes/write>");
	nloop = atoi(argv[1]);
	totalnbytes = atoi(argv[2]) * 1024 * 1024;
	xfersize = atoi(argv[3]);

	buf = Valloc(xfersize);
	Touch(buf, xfersize);
	buf->mtype = 1;

	Pipe(contpipe);
	msqid = Msgget(IPC_PRIVATE, IPC_CREAT | SVMSG_MODE);

	if ( (childpid = Fork()) == 0) {
		writer(contpipe[0], msqid);		/* child */
		exit(0);
	}
	Start_time();
	for (i = 0; i < nloop; i++)
		reader(contpipe[1], msqid, totalnbytes);
	printf("bandwidth: %.3f MB/sec\n",
		   totalnbytes / Stop_time() * nloop);

	kill(childpid, SIGTERM);
	Msgctl(msqid, IPC_RMID, NULL);
	exit(0);
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
	int readid, writeid;
	key_t Rkey, Wkey;
	
	Rkey = Ftok("/tmp/msg", 0);
	Wkey = Ftok("/tmp/msg2", 0);

	readid = Msgget(Rkey, 0644 | IPC_CREAT);
	writeid = Msgget(Wkey, 0644 | IPC_CREAT);

	server(readid, writeid);


	exit(EXIT_FAILURE);
}
Exemplo n.º 8
0
int
main(int argc, char **argv)
{
	int		readid, writeid;

		/* 4assumes server has created the queues */
	writeid = Msgget(MQ_KEY1, 0);
	readid = Msgget(MQ_KEY2, 0);

	client(readid, writeid);

		/* 4now we can delete the queues */
	Msgctl(readid, IPC_RMID, NULL);
	Msgctl(writeid, IPC_RMID, NULL);

	exit(0);
}
Exemplo n.º 9
0
int
main(int argc, char **argv)
{
	int		readid, writeid;

	/* server must create its well-known queue */
	writeid = Msgget(MQ_KEY1, 0);
	/* we create our own private queue, and in client() we tranport our queue id to server */
	readid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT);

	client(readid, writeid);

	/* work done , and delete our private queue */
	Msgctl(readid, IPC_RMID, NULL);

	exit(0);
}
Exemplo n.º 10
0
int Snd(int dest, void *structure, int size) {
	
	dest = Msgget(dest, 0);
	if (dest == -1) {
		return -1;
	}
	
	Printf2("Sending special message to %d", dest);
	return Msgsnd(dest, structure, size, 0);
}
Exemplo n.º 11
0
int
main(int argc, char **argv)
{
	int		msqid;

		/* 4server must create the queue */
	msqid = Msgget(MQ_KEY1, 0);

	client(msqid, msqid);	/* same queue for both directions */

	exit(0);
}
Exemplo n.º 12
0
int main(int argc, char **argv)
{
	int mqid;

	if (argc != 2)
		err_quit("Usage: rmid <pathname>");

	mqid = Msgget(Ftok(argv[1], 0), 0);
	Msgctl(mqid, IPC_RMID, NULL);

	exit(0);
}
Exemplo n.º 13
0
int
main(int argc, char **argv)
{
	int		i, msqid;

	for (i = 0; i < 10; i++) {
		msqid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT);
		printf("msqid = %d\n", msqid);

		Msgctl(msqid, IPC_RMID, NULL);
	}
	exit(0);
}
Exemplo n.º 14
0
int SndCompactMessage(int dest, type_t type, int value, int id) {
	
	Printf2("Sending compact message to %d of type %ld", dest, type);
	
	dest = Msgget(dest, 0);
	if (dest == -1) {
		return -1;
	}
	CLEAR(compactMessage);
	compactMessage.type = type;
	compactMessage.content.value = value;
	compactMessage.content.id = (id == -1) ? GetMessageID() : id;

	return Msgsnd(dest, &compactMessage, sizeof(compactMessage), 0);
}
Exemplo n.º 15
0
int
main(int argc, char **argv)
{
    int		c, oflag, mqid;

    oflag = SVMSG_MODE | IPC_CREAT;
    while ( (c = Getopt(argc, argv, "e")) != -1) {
        switch (c) {
        case 'e':
            oflag |= IPC_EXCL;
            break;
        }
    }
    if (optind != argc - 1)
        err_quit("usage: msgcreate [ -e ] <pathname>");

    mqid = Msgget(Ftok(argv[optind], 0), oflag);
    exit(0);
}
Exemplo n.º 16
0
int main(int argc, char **argv)
{
	int msqid;
	struct msqid_ds info;
	struct msgbuf buf;

	msqid = Msgget(IPC_PRIVATE, IPC_CREAT | SVMSG_MODE);

	buf.mtype = 1;
	buf.mtext[0] = 1;
	Msgsnd(msqid, &buf, 1, 0);

	Msgctl(msqid, IPC_STAT, &info);
	printf("read-write: %03o, cbytes = %lu, qnum = %lu, qbytes = %lu\n", info.msg_perm.mode & 0777, (ulong) info.msg_cbytes, (ulong) info.msg_qnum, (ulong) info.msg_qbytes);

	system("ipcs -q");

	Msgctl(msqid, IPC_RMID, NULL);
	exit(0);
}
Exemplo n.º 17
0
int main(int argc, char **argv)
{
	int mqid;
	size_t len;
	long type;
	struct msgbuf *ptr;

	if (argc != 4)
		err_quit("Usage: msgsnd <pathname> <#bytes> <type>");
	len = atoi(argv[2]);
	type = atoi(argv[3]);

	mqid = Msgget(Ftok(argv[1], 0), MSG_W);

	ptr = (struct msgbuf *)Calloc(sizeof(long) + len, sizeof(char));
	ptr->mtype = type;

	Msgsnd(mqid, ptr, len, 0);

	exit(0);
}