#include #include #include #include #include #include using namespace std; int main() { int i; ofstream outFile("ReadData"); outFile << i; for(i = 1; i < 10000; ++i) { outFile << " " << i << endl; } outFile.close(); ifstream inFile("ReadData"); pid_t forkID(fork()); if( forkID == -1) { perror("Fork: "); return 1; } pid_t mypid = getpid(); inFile >> i; while(inFile) { cout << i << " " << mypid << endl; inFile >> i; } inFile.close(); cout << endl << endl << endl; int fd{open("ReadData", O_RDONLY)}; char c; while(read(fd, &c, 1) == 1) { cout << c << " " << mypid << endl; } close(fd); return 0; }