Why is there a type for process ids (pid_t), but not for file descriptors (fd)

cdevelopmentfilesposixprocess

I see that pid_t is typedef'd in unistd.h, and file descriptors are defined to be int in fcntl.h. But since they are used in similar ways, wouldn't it make sense to have a typedef for file descriptors?

Best Answer

Before reading the other responses, my guess was that pid_t exists for portability reasons. In the Good Ol' Days, some Unixes had short PIDs, others had int PIDs, so you define a system-specific type for PID. I can't recall any pain involved in using int for a file descriptor, even in the very early days of 64-bitness.

Related Question