Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!vector!rpp386!jfh From: jfh@rpp386.UUCP (The Beach Bum) Newsgroups: comp.unix.xenix Subject: Re: Test SCO Xenix IPC reliability Summary: and here is the message queue version ... Message-ID: <5872@rpp386.UUCP> Date: 26 Aug 88 17:17:29 GMT References: <22012@neabbs.UUCP> <5786@rpp386.UUCP> <128@jetson.UPMA.MD.US> <5867@rpp386.UUCP> Reply-To: jfh@rpp386.UUCP (The Beach Bum) Organization: HASA, "S" Division Lines: 100 In article <5867@rpp386.UUCP> jfh@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 #include #include #include 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@rpp386.UUCP) HASA, "S" Division "If the code and the comments disagree, then both are probably wrong." -- Norm Schryer