Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does getpid() return pid_t instead of int?

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 ints etc.?

like image 429
ntl0ve Avatar asked Sep 11 '11 14:09

ntl0ve


People also ask

Is pid_t the same as int?

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 .

What is the return value of getpid () when called from a parent process?

The getpid() function returns the process ID of the calling process. The getpgrp() function returns the process group ID of the calling process.

Can I use int for PID?

Using int is probably not a good idea since it would not support hypothetical future implementations with 64-bit pids.


1 Answers

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).

like image 85
zvrba Avatar answered Oct 02 '22 23:10

zvrba