fast writes interruptable on SunOS 4.1.1
Pond Scum
hue at island.COM
Thu Feb 7 20:03:19 AEST 1991
(It's sorta internals - it has to do with sleeping at PZERO or lower, right?)
Here is a program that shows that writes to a regular file are interruptable
and not restartable under SunOS 4.1.1. Under SunOS 4.0.3 on Sun 3 and 4c,
HP-UX 7.0 on a 9000/370, and AIX 3.1 on an RS/6000 (no particular reason for
choosing them, that's just what's near my cube) the writes are not interrupted
and always complete. Under SunOS 4.1.1 on a 4c, the writes are interrupted.
-----------
#include <sys/types.h>
#include <fcntl.h>
#include <sys/time.h>
#include <signal.h>
#include <stdio.h>
#include <errno.h>
static void alrm();
static char bigbuf[0x100000];
static struct sigvec v = {alrm, 0, 0};
static struct itimerval it = {{0, 500000}, {0, 500000}}; /* half sec */
static void
alrm()
{
fputs("Ow, my head!\n", stderr);
}
main(argc, argv)
int argc;
char **argv;
{
int i, fd, nw;
for (i = 0; i < 0x100000; i++)
bigbuf[i] = i & 0xff;
sigvec(SIGALRM, &v, 0);
setitimer(ITIMER_REAL, &it, 0);
if ((fd = open("bigfile", O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
{
perror("bigfile");
exit(1);
}
for (i = 0; i < 10; i++)
{
errno = 0;
nw = write(fd, bigbuf, sizeof(bigbuf));
if (nw < 0)
{
perror("bigfile");
}
else if (nw != sizeof(bigbuf))
{
if (errno)
{
fprintf(stderr, "interrupted write, %d of %d got written\n",
nw, sizeof(bigbuf));
}
else
{
fprintf(stderr, "short write, %d of %d got written\n",
nw, sizeof(bigbuf));
}
}
}
return(0);
}
--
"It reminds me of how in the computer industry they use the word "user", which
to them means "idiot"" -Dave Barry
Jonathan Hue, Senior Coding Pig Island Grapics Corp. Graphic Arts Division
4000 Civic Center Drive San Rafael, CA {uunet,sun}!island!hue hue at island.com
More information about the Alt.sys.sun
mailing list