#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc, char *argv[]) {
   pid_t id ;
   char s[10];

   printf("I'm process %d", getpid());
   printf(", press enter to create a new process...");
   fgets(s,2,stdin); // pause for user input

   id = fork();

   printf("\nWe are now 2 processes.\n");
   printf("But with different pids : %d\n", getpid());

   int increment = 2;
   int i = 0;
   for (i = 0; i < 20; i += increment) {
      printf("i=%d, (pid %d)\n", i, getpid());
      /* sleep(1); */
   }

   /* fgets(s,2,stdin); // pause for user input */

   if ( id == 0) {
      /* Only the CHILD process executes this code */
      printf("I'm Luke, my pid is: %d\n", getpid());
      printf("I'm Luke, I'm the child of: %d\n", getppid());

   } else {
      /* Only the PARENT process executes this code */
      printf("Luke (%d), I'm your father (%d)\n", id, getpid());
   }

   printf("Goodbye from %d\n", getpid());
   return EXIT_SUCCESS;
}





/*pstree -psh #process*/
/*pmap -p #process*/














   /* for (int i = 0; i < 20; i += increment) { */
      /* printf("i=%d, (pid %d)\n", i, getpid()); */
      /* sleep(1); */
   /* } */
// vim:guifont=Monospace\ 15
