#include <iostream>
#include <unistd.h>
#include <sys/wait.h>

using namespace std;

int main(){
	pid_t pid = fork();
	if (pid == 0){
		cout << "Child exits immediately\n";
		_exit(0);
	}
	else {
		sleep(6); // Child becomes zombie
		// parent is running without a blocking wait for the child
		cout << "Parent calling a child\n";
		waitpid(pid,nullptr,0); // zombie now retrieved
		cout << "zombie - parent alive while the child is dead\n";
	}

	return 0;
}
