Comment

Comment by joosters

Following is the c-programming example which explains how fork system call works.

  shashi@linuxtechi ~}$ vim 1_fork.c
  #include<stdio.h>
  #include<unistd.h>
  Int main(void)
  {
  printf("Before fork\n");
  fork();
  printf("after fork\n");
  }
  shashi@linuxtechi ~}$ 
  shashi@linuxtechi ~}$ cc 1_fork.c
  shashi@linuxtechi ~}$ ./a.out
  Before fork
  After fork
  shashi@linuxtechi ~}$
How exactly is that demonstrating how fork() works? The article is completely missing any explanation - like why 'After fork' was only printed once and not twice as would be initially expected (It's unclear to me: while stdio buffering can cause strangeness if you don't flush buffers before a fork(), surely in this case both processes will exit cleanly and should flush their post-fork outputs?)
parent joosters 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton