#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>


using namespace std;

int main(void){
	int k=3;
	int status;
	pid_t pid;
	pid=fork();
//	k=2;
	if (pid<0) {
		cout<< "Fork() error !" << endl;
		_exit(1);
	}
	if (pid==0) {
		k=2;
		//child process
		cout << "Child process PID=" <<getpid() << "   Parent process PID=" << getppid() << endl;
		sleep(10);
		cout <<" Child k=" << k <<endl;
		_exit(200);
	}else{
		//Parent process
		cout << "Parent process," <<"PIDR=" << pid << " PID=" << getpid() <<"   Parent process PID=" << getppid() << endl;
		cout <<" Parent k=" << k << endl; 
		pid = wait(&status);

				//catch wait
		if(WIFEXITED(status)) {
			cout << "Process PID" << pid << "finished with code :" << WEXITSTATUS(status)
				<< "from process with PID:" << getpid() << endl;
		}
	}


return 0;
}


