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?
Why is there a type for process ids (pid_t), but not for file descriptors (fd)
cdevelopmentfilesposixprocess
Best Answer
Before reading the other responses, my guess was that
pid_t
exists for portability reasons. In the Good Ol' Days, some Unixes hadshort
PIDs, others hadint
PIDs, so you define a system-specific type for PID. I can't recall any pain involved in usingint
for a file descriptor, even in the very early days of 64-bitness.