#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>

//CSE 660
//Jason Kim

using namespace std;

int main()
{	
	int file1,file2,bsize;
	int pidb;
	char buf[BUFSIZ];
	pidb = getpid();

	cout << "Process B starting with pid of " << pidb << endl;	
	file2 = open("/usr/class/cis660/x.x",O_RDONLY); //opens up x.x
	file1 = creat("XYZ.txt",S_IRWXU);
	lseek(file2,-200,SEEK_END); // move 200 chars from the end end in x.x
	
	read(file2,buf,200); //reads the last 200 characters
	write(file1,buf,10);//writes them
	//writes from file x.x last 200 characters

	close(file1); //close files
	close(file2);
	cout << "Process B Terminating" << endl;
	exit(1);
	return 0;
}

