fork combined with redirection

From: Prakash Prabhu (prakash.prabhu_at_gmail.com)
Date: 01/25/05


Date: 25 Jan 2005 03:14:35 -0800

Hi ,

I ran the following code with output redirected to a file . I got weird
results ( or is that the
expected output ) ?

#include<stdio.h>
int main()
{
printf("\n Hello ");
if ( fork() == 0 )
{
printf("\n World");
}
return 0;
}

$ gcc -o hello hello.c
$ ./hello > out
$ cat out
  Hello
  World
  Hello

Why is Hello being printed twice ?



Relevant Pages

  • RE: cat installing under Vista x64
    ... HlkServiceDesc = "Aladdin Hardlock Legacy Driver" ... I've build a .cat using makecat -v hardlock.cdf from following file: ... int DestSize) ... printf("CryptCATAdminAcquireContext failed error %d\n",GetLastError()); ...
    (microsoft.public.development.device.drivers)
  • Re: suggested addition to date
    ... It is not a command to filter files. ... 'cat' would be a more ... int bflag, eflag, nflag, sflag, tflag, vflag; ... const char *filename; ...
    (freebsd-current)
  • isfinite
    ... $ man -w isfinite ... I dev.man.irix_lib 06/29/2004 Development Environment IRIX Manual Pages ... $ cat foo.c ... int main ...
    (comp.sys.sgi.bugs)
  • Re: [PATCH 1/3] Fix Unlikely(x) == y
    ... altogether for these cases; unlikelyis almost a ... go-faster-stripes thing, and if you don't know how to use it you ... $ cat branch.c ... int main ...
    (Linux-Kernel)
  • Re: suggested addition to date
    ... It is not a command to filter files. ... 'cat' would be a more ... int bflag, eflag, nflag, sflag, tflag, vflag; ... const char *filename; ...
    (freebsd-current)