News for hackers. Stuff that matters.
Re:Learn and use fork(), vfork(), wait() and exec() system c... by joosters on Wednesday October 30, 2019 @03:16PM (#21401425)
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?)
Re:Learn and use fork(), vfork(), wait() and exec() system c... by DSMan195276 on Wednesday October 30, 2019 @03:44PM (#21401727)
It should print `after fork` two times, they just wrote it wrong. They clearly wrote the whole thing manually, since they used `vim` and not `cat` to display the contents of the file, and they show it printing `After fork` and not `after fork`. I think they just forgot to put the line twice. The fact that they have `Int` and not `int` means their example doesn't actually compile, so I don't think they tested this one.
Re:Learn and use fork(), vfork(), wait() and exec() system c... by tyingq on Wednesday October 30, 2019 @03:52PM (#21401811)
Sure but doesn't address the article mentions of vfork, wait, waitpid, kill, etc. Or other unmentioned stuff, like variations of kill/killpid().
Re:Learn and use fork(), vfork(), wait() and exec() system c... by moltensodium on Wednesday October 30, 2019 @04:02PM (#21401908)
This example is wrong, it should print "after fork" twice as both processes would run that.