What's the logic behind calls like getpid()
returning a value of type pid_t
instead of an unsigned int
? Or int
? How does this help?
I'm guessing this has to do with portability? Guaranteeing that pid_t
is the same size across different platforms that may have different sizes of int
s etc.?
The pid_t data type is a signed integer type which is capable of representing a process ID. In the GNU library, this is an int .
The getpid() function returns the process ID of the calling process. The getpgrp() function returns the process group ID of the calling process.
Using int is probably not a good idea since it would not support hypothetical future implementations with 64-bit pids.
I think it's the opposite: making the program portable across platforms, regardless of whether, e.g., a PID is 16 or 32 bits (or even longer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With