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

Re: restoring stdin as keyboard 80 80

Make a copy of 0 using dup() before you close it, so that you can dup() it again to get back to it.


keep = dup(0);
dup(fd);  // fd is now stdin
dup(keep); // back to original stdin
commented: Right +4
Re: restoring stdin as keyboard 80 80

But isn't it stored atomatically by the kernel?

Re: restoring stdin as keyboard 80 80

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.