Comment

Comment by phoyd

Under UNIX, the lowest available file descriptor for the process is returned from open/create (also in Posix). So if you close(0) and then immediately open() something, you will (probably) get 0 as the new file descriptor.

This is the way redirection was done in early UNIX versions, at least I think until System 7, where dup2() was introduced to address the race condition lurking here.

parent phoyd 3 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton