Hello All,
Supose we do close(0) and the dup it to another file descripter to use the new file as the stdin input.
Is there anyway to restore the keyboard as the standard input in the same program
Thanks,
Majoni
Hello All,
Supose we do close(0) and the dup it to another file descripter to use the new file as the stdin input.
Is there anyway to restore the keyboard as the standard input in the same program
Thanks,
Majoni
Make a copy of 0 using dup() before you close it, so that you can dup() it again to get back to it.
IIRC
keep = dup(0);
close(0);
dup(fd); // fd is now stdin
close(0);
dup(keep); // back to original stdin
Thanks
But isn't it stored atomatically by the kernel?
Why would it be?
It doesn't mean a damn thing to the kernel, it's just an open file descriptor owned by a process.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.