#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
using namespace std;
int main(void) {
int k=3;
int status;
pid_t pid; //process id
pid=fork();
//k=2;
if (pid<0) { 
   cout<<"fork() error :) "<<endl;
   _exit(1); //with dash! "lightest" one (other is without dash simple exit(1) )
}
if (pid==0) {
//child  process
k=2;
  cout<<"child process PID= "<<getpid() <<"parent process pid="  //get pid of child
  << getppid() << endl;
  sleep(10);
  cout<<"child is k="<< k <<endl;
  _exit(200);
} else {
//parent process
cout<< "parent process,"<< " PIDR= "<< pid                    
<<"PID="<< getpid() << "parernt process PID="
<< getppid() << endl;
cout<<"parent k"<< k <<endl;                                     //same time k=2 for both child and parent AT THE SAME TIME
pid=wait(&status);
 if (WIFEXITED(status)) {
cout<<" process pid" << pid << "finished with code :" << WEXITSTATUS(status)
<<"from process with PID:"<< getpid() << endl;
}
}
return 0;
}
// if and else same time parallel!

