#include <stdio.h>
#include <string.h>

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

int main()
{	
	FILE *tmp;
	pid_t flag;
	int counter;
	char msg[100];

	strcpy(msg, "hi");
	tmp = fopen("tmp.txt", "w");
	fputs(msg, tmp);
	fclose(tmp);
	
	flag = fork();

	if(flag) {
		for(counter = 1; counter <= 10; counter++) { 
			tmp = fopen("tmp.txt", "r");
			fscanf(tmp, "%s", &msg);
			fclose(tmp);
			printf("%s\n", msg);
			sleep(1);
		}
		wait(0);
		return(0);
	} else {
		scanf("%s", &msg);
		tmp = fopen("tmp.txt", "w");
		fprintf(tmp, "%s", msg);
		fclose(tmp);
	}

}
