#include #include int main() { printf("Okay, we are going to read from a copy of stdin (fd 0).\n"); printf("First, we make the copy with dup():\n"); int new_fd = dup(0); printf("Okay, the new file descriptor is %d...\n",new_fd); printf("Let's try reading from it...\n\n"); char buffer[4096]; int bytes = read(new_fd,buffer,4095); if(bytes > 0) { buffer[bytes] = (char )0; printf("Okay, we read these bytes: '%s'\n",buffer); printf("All finished!\n"); } else { printf("(Didn't read)...\n"); } }