🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.internals
Article #2393

Re: printf() & fork() ......

#2393
From: Mike Swiston
Date: Sun, 22 Nov 1992 02:07
34 lines
1090 bytes
In <1992Nov19.133035.172@ccsun7.csie.nctu.edu.tw> mchuang@csie.nctu.edu.tw (Ming-Chuan Huang) writes:

% #include <stdio.h>

% program 1:

% void main()
% {
%     printf("Hello ");
%     if (fork() == 0)
%         printf("world\n");
% }

% result:
% Hello Hello world

Under turbo cshell, I get the output:
Hello world
Hello  Exit 1

leading me to guess that the problem is that
your output buffer isn't getting flushed the
way you might expect it to be.  You can fix
that like so:

#include <stdio.h>

void main()
{
    printf("Hello ");
    fflush(stdout);
    if (fork() == 0)
        printf("world\n");
}
Technical Details
Message-ID: <alchemy.722398030@cs1.bradley.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!ux1.cso.uiuc.edu!bradley.bradley.edu!cs1!alchemy
References: <1992Nov19.133035.172@ccsun7.csie.nctu.edu.tw>

Show Full Headers
Complete Article Headers
Newsgroups: comp.unix.internals
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!ux1.cso.uiuc.edu!bradley.bradley.edu!cs1!alchemy
From: alchemy@cs1.bradley.edu (Mike Swiston)
Subject: Re: printf() & fork() ......
Message-ID: <alchemy.722398030@cs1.bradley.edu>
Sender: news@bradley.bradley.edu
Organization: salt of the earth in open wounds.
References: <1992Nov19.133035.172@ccsun7.csie.nctu.edu.tw>
Date: 22 Nov 92 02:07:10 GMT
Lines: 34