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

int main(int argc, char *argv[]) {
  printf("hello (pid:%d)\n", (int) getpid());
  int rc = fork();
  if (rc < 0) {         // fork başarısız oldu; programı sonlandır.
    fprintf(stderr, "fork failed\n");
    exit(1);
  } else if (rc == 0) { // Yeni oluşturulan child process bu dalı yürütür.
    printf("child (pid:%d)\n", (int) getpid());
  } else {              // Parent process bu dalı yürütür.
    int rc_wait = wait(NULL);
    printf("parent of %d (rc_wait:%d) (pid:%d)\n",
            rc, rc_wait, (int) getpid());
  }
  return 0;
}
