Test SCO Xenix IPC reliability

The Beach Bum jfh at rpp386.UUCP
Sat Aug 27 03:17:29 AEST 1988


In article <5867 at rpp386.UUCP> jfh at rpp386.UUCP (The Beach Bum) writes:
>the new version uses message queues and screams like a banshee.  that
>should be final proof as to how bullet proof the message queues are
>under xenix.

and here it is.  i actually developed this on pigs, a 68020 vme bus
machine.  the code compiled first time out on rpp386.  portable, no?

just a brief overview - the parent and child swap "TICK ...." and
".... TOCK" message back and forth using a message queue.  two 
different type messages are used.  type 1 is from the parent and
is expected by the child.  type 2 is from the child and is expected
by the parent.  this insures the two processes remain synchronized.

for a really good work out, run this on the console.  if you want
to prove there are NO bugs in the message passing code (despite
what certain SCO bashers will say) run this in the background with
a real high nice for a few days.  a bug fixed version of the shared
memory tester could also be run to further bebunk the sco nay-sayers.
what the heck, run them both in the background with a nice of say,
plus 20, for a couple of days.  that should find any kinks.
------------------------ cut and save as msgque.c ----------------------
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <signal.h>

key_t	msgkey = ('m' << 8) | 's';
int	msgqid;
struct	mymsgbuf {
	int	mytype;
	char	mytext[11];
};
struct	mymsgbuf pmsg = { 1, "TICK ....\n" };
struct	mymsgbuf cmsg = { 2, ".... TOCK\n" };

int	childpid;

parent ()
{
	struct	mymsgbuf buf;

	while (1) {
		memset (&buf, sizeof buf, 0);

		if (msgrcv (msgqid, &buf, sizeof buf.mytext, 2L, 0) < 0)
			perror ("parent: msgrcv");

		write (1, buf.mytext, sizeof buf.mytext);

		if (msgsnd (msgqid, &pmsg, sizeof pmsg.mytext, 0) < 0)
			perror ("parent: msgsnd");
	}
}

child ()
{
	struct	mymsgbuf buf;

	while (1) {
		memset (&buf, sizeof buf, 0);

		if (msgrcv (msgqid, &buf, sizeof buf.mytext, 1L, 0) < 0)
			perror ("child: msgrcv");

		write (1, buf.mytext, sizeof buf.mytext);

		if (msgsnd (msgqid, &cmsg, sizeof cmsg.mytext, 0) < 0)
			perror ("child: msgsnd");
	}
}

main ()
{
	if ((msgqid = msgget (msgkey, IPC_CREAT|0666)) == -1) {
		perror ("msgget");
		exit (1);
	}
	switch (childpid = fork ()) {
		default:
			/* prime the pump ... */
			if (msgsnd (msgqid, &pmsg, sizeof pmsg.mytext, 0)) {
				perror ("msgsnd");
				kill (childpid, 9);
				exit (1);
			}
			parent ();
		case 0:
			child ();
		case -1:
			perror ("fork");
			exit (1);
	}
	exit (1);
}
-- 
John F. Haugh II (jfh at rpp386.UUCP)                           HASA, "S" Division

    "If the code and the comments disagree, then both are probably wrong."
                -- Norm Schryer



More information about the Comp.unix.xenix mailing list