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

using namespace std;

int main(void){
	int k=2;
	int status;
	pid_t pid;
	pid=fork();
	if (pid<0){
		cout << "Fork() Error !";
		_exit(-1);
	}

	if (pid==0){
		//child process
		k=2;
		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);
		if (WIFEXITED(status)){
			cout <<"Process Pid:" << pid <<"Finished with code :" << WEXITSTATUS(status) << "from process with PID:" <<getpid() <<endl;
		}

	}


return 0;
};
