Test SCO Xenix IPC reliability
The Beach Bum
jfh at rpp386.UUCP
Mon Aug 22 15:19:17 AEST 1988
Someone was screaming about how unrealiable IPC (such as shared memory)
on SCO Xenix was. I whipped this program up originally back during the
great volatile debate and only discovered it again tonigh while cleaning
out my home directory. When run it prints out
TICK ...
... TOCK
forever as each process gets a chance to execute. The code is short
enough that you should be able to understand what is going on. If
you can run this without any trouble then your shared memory is working
just fine. Otherwise, you have troubles ...
- John.
---------------------- clip out and save as volatile.c ----------------
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <signal.h>
int zero = 0;
int *loc = &zero;
int key = ('v' << 8) | 'o';
catch (sig)
int sig;
{
signal (sig, catch);
}
parent ()
{
while (1) {
while (*loc)
;
write (1, "TICK ....\n", 10);
*loc = 1;
kill (loc[2], SIGUSR1);
pause ();
}
}
child ()
{
while (1) {
while (! *loc)
;
write (1, ".... TOCK\n", 10);
*loc = 0;
kill (loc[1], SIGUSR1);
pause ();
}
}
main ()
{
int id;
if ((id = shmget (key, 3 * sizeof (int), IPC_CREAT|0666)) == -1) {
perror ("shmget");
exit (1);
}
if ((loc = (int *) shmat (id, (char *) 0, 0)) == (int *) 0) {
perror ("shmat");
exit (1);
}
loc[0] = 0;
switch (fork ()) {
default:
loc[1] = getpid ();
signal (SIGUSR1, catch);
parent ();
case 0:
loc[2] = getpid ();
signal (SIGUSR1, catch);
child ();
case -1:
perror ("fork");
exit (1);
}
exit (1);
}
--
John F. Haugh II +--------- Cute Chocolate Quote ---------
HASA, "S" Division | "USENET should not be confused with
UUCP: killer!rpp386!jfh | something that matters, like CHOCOLATE"
DOMAIN: jfh at rpp386.uucp | -- apologizes to Dennis O'Connor
More information about the Comp.unix.xenix
mailing list