Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: