From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11035d,e18150a7d0814fcb,start X-Google-Attributes: gid11035d,public X-Google-Thread: fee84,e18150a7d0814fcb,start X-Google-Attributes: gidfee84,public X-Google-Thread: f7cee,e18150a7d0814fcb,start X-Google-Attributes: gidf7cee,public X-Google-Thread: 10c665,e18150a7d0814fcb,start X-Google-Attributes: gid10c665,public X-Google-ArrivalTime: 1994-05-27 03:35:52 PST Path: bga.com!news.sprintlink.net!rtp.vnet.net!news1.digex.net!news.intercon.com!panix!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!lll-winken.llnl.gov!fastrac.llnl.gov!s1.gov!overload.lbl.gov!eubie.lbl.gov!jin From: jin@eubie.lbl.gov (Guojun Jin[ITG]) Newsgroups: comp.unix.osf.osf1,comp.unix.solaris,comp.unix.sys5.r4,comp.bugs.sys5 Subject: Fork bug in Sys5 (or similar) system Date: 25 May 1994 22:16:32 GMT Organization: Lawrence Berkeley Laboratory Distribution: inet Message-ID: <2s0io0$248@overload.lbl.gov> NNTP-Posting-Host: eubie.lbl.gov Xref: bga.com comp.unix.osf.osf1:1735 comp.unix.solaris:8086 comp.unix.sys5.r4:1876 comp.bugs.sys5:41 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 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