为什么getpid()返回pid_t而不是int? [英] Why does getpid() return pid_t instead of int?

查看:203
本文介绍了为什么getpid()返回pid_t而不是int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getpid()这样的调用背后的逻辑是什么?返回类型的值 pid_t而不是unsigned int?还是int?这有什么帮助?

我猜想这与可移植性有关吗?保证pid_t在不同平台上具有相同的大小,并且可能具有不同的int s等大小??

解决方案

我认为是相反的:使程序可以跨平台移植,而不管PID是16位还是32位(甚至更长). /p>

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

解决方案

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

这篇关于为什么getpid()返回pid_t而不是int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆