Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Fork bug in Sys5 (or similar) system
@ 1994-05-25 22:16 Guojun Jin[ITG]
  1994-05-26  7:52 ` Casper H.S. Dik
  1994-05-26 18:08 ` Doug Gwyn (ACISD/MCSB) <gwyn>
  0 siblings, 2 replies; 12+ messages in thread
From: Guojun Jin[ITG] @ 1994-05-25 22:16 UTC (permalink / 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 |


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1994-06-01 22:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-05-25 22:16 Fork bug in Sys5 (or similar) system Guojun Jin[ITG]
1994-05-26  7:52 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox