#include <stdio.h>
#include <cstdlib>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
using namespace std;

int main(void) {
        int k=3;
        int status;
        pid_t pid;
        pid=fork();
        //k=2;
        if (pid<0) {
                 cout << "Fork() error !";
                 _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);
                if (WIFEXITED(status)) {
                cout << "Process PID" << pid << "finished with code :" <<WEXITSTATUS(status)
                     << "from process with PID:" << getpid() << endl;
                     }
        }
        return 0;
}
