Xref: utzoo comp.unix.internals:1982 alt.sys.sun:2650 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!island!hue From: hue@island.COM (Pond Scum) Newsgroups: comp.unix.internals,alt.sys.sun Subject: fast writes interruptable on SunOS 4.1.1 Message-ID: <3666@island.COM> Date: 7 Feb 91 09:03:19 GMT Followup-To: alt.sys.sun Organization: Island Graphics Corp., San Rafael, CA Lines: 75 (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 #include #include #include #include #include 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@island.com