#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.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());
    char *myargs[3];
    myargs[0] = strdup("wc");   // Çalıştırılacak programın adı: "wc".
    myargs[1] = strdup("p3.c"); // Programa argüman olarak verilecek girdi dosyası.
    myargs[2] = NULL;           // NULL, argüman dizisinin sonunu belirtir.
    execvp(myargs[0], myargs);  // wc programını mevcut process içinde çalıştır.
    printf("this shouldn’t print out");
  } 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;
}
