From: jin@eubie.lbl.gov (Guojun Jin[ITG])
Subject: Fork bug in Sys5 (or similar) system
Date: 25 May 1994 22:16:32 GMT [thread overview]
Message-ID: <2s0io0$248@overload.lbl.gov> (raw)
In sys5 or similar system, the fork() will misplace a file position in a pointer
which opened by a parent and passed to children. The bugs affects only fread().
fwrite() has not been tested yet, but similar peoblem should exist.
The tested systems are:
HP-UX A.09.01 A 9000/720
DEC OSF/1 V1.3A (Rev. 112)
SunOS 5.4 ea1 sparc
IRIX 5.2 02282015 IP19 mips (fixed)
------------------------------ Cut Here ------------------------------
/* SV5 fork - fread bug . c
#
% Usages:
% a.out [nrR] < fork-sv5.c
% n or nothing = no fork and use gets to input
% R = no fork and use fread to input
% r = fork and use fread to input !!! bug here
% * all others = fork and use gets to input
%
% Author: Jin Guojun - LBL
*/
#include <stdio.h>
main(argc, argv)
char **argv;
{
char buf[256];
FILE *fp = stdin;
/* first read in main() */
if (argc > 1 && *argv[1] == 'r')
read_sbur(fp, buf, 0);
else printf("start:\n%s", fgets(buf, 128, fp));
/* second read in either parent or child */
if (argc > 1 && *argv[1] != 'n' && *argv[1] != 'R') {
switch (fork()) {
case 0: if (argc > 1 && *argv[1] == 'r')
read_sbur(fp, buf, 1);
else subr(fp, buf);
printf("done fork");
break;
case -1:printf("fork error\n");
exit(-1);
default:printf("FORK\n");
}
} else { /* in parent */
if (argc > 1 && *argv[1] == 'R')
read_sbur(fp, buf, 1);
else subr(fp, buf);
printf("end no fork\n");
}
exit(0);
}
read_sbur(fp, buf, more)
FILE *fp;
char* buf;
{
do { int i, j = fread(buf, 1, 80, fp);
for (i=0; i<j; i++) putchar(buf[i]);
} while (more && !feof(fp));
}
subr(fp, buf)
FILE *fp;
char *buf;
{
while (!feof(fp))
printf("%s", fgets(buf, 128, fp));
}
------------------------------ Cut Here ------------------------------
--
/-------------- Jin Guojun ------------ v ---- Internet: g_jin@lbl.gov ----\
| Imaging & Distributed Computing | Usenet: ucbvax!g_jin@lbl.gov |
| Lawrence Berkeley Laboratory | Bitnet: -- |
| 50B-2239, Berkeley, CA 94720 - jin%george.lbl.gov@Csa3.LBL.Gov |
next reply other threads:[~1994-05-25 22:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-05-25 22:16 Guojun Jin[ITG] [this message]
1994-05-26 7:52 ` Fork bug in Sys5 (or similar) system Casper H.S. Dik
1994-05-26 18:16 ` William Armitage
1994-05-27 8:48 ` Casper H.S. Dik
1994-05-27 12:59 ` Dave Johnson
1994-05-27 13:40 ` Casper H.S. Dik
1994-05-28 2:51 ` Doug Gwyn (ACISD/MCSB) <gwyn>
1994-05-31 1:25 ` Peter da Silva
1994-05-26 18:08 ` Doug Gwyn (ACISD/MCSB) <gwyn>
1994-05-31 19:34 ` Guojun Jin[ITG]
1994-05-31 20:07 ` Casper H.S. Dik
1994-06-01 22:06 ` Peter da Silva
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox