#include #include #include #include #include #include static char *str1 = "OP1\n"; int main() { int f1, f2; close(STDOUT_FILENO); f1 = open ("myjunk", O_RDWR | O_CREAT | O_TRUNC, 0777); close(STDERR_FILENO); f2 = dup(f1); printf("print to standard output!!!, f1 = %d\n", f1); // fflush(0); fprintf(stderr, "print to standard error!!!\n"); // fflush(0); write(f1, str1, strlen(str1)); // fflush(0); close(f1); // close f1. now fid 1 is available close(f2); open("/dev/tty", O_WRONLY); // open tty, relink fid 1 to tty printf("This is a test\n"); // before this printf // another two printfs will also be performed (to tty). return 0; }