unix进程ID的基数是10吗?
在阅读了一系列手册页并通过谷歌搜索后,我决定将这个问题发布给堆栈溢出的聪明人。
我正在开发一个基本的 Unix Shell,其中一个要求是我必须实现一个命令来以 10 进制 ASCII 形式回显 shell 的 pid...在我阅读此要求之前,我假设进程 id 已经是基本的10 个数字。有谁知道这是真的吗?
After reading a series of man pages and searching through google, I decided to post this question to the bright folks of stack overflow.
I'm working on a basic Unix Shell and one of the requirements is that I have to implement a command to echo out the shell's pid in base 10 ASCII... Before I read this requirement, I had assumed that process id's were already base 10 numbers. Does anyone know if this is true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从技术上讲,
getpid()
返回的数字以 2 为基数。 :-)认真地说,该要求可能只是意味着数字应该显示为十进制数字,而不是十六进制数字。不过,我会要求澄清这一要求,因为你不得不问。
Technically speaking, the numbers that are returned by
getpid()
are in base two. :-)Seriously speaking, the requirement probably just means that the number should be displayed as a decimal number as opposed to, for example, a hexadecimal number. I would ask for clarification of that requirement though, since you had to ask.
数字本身没有底数。它们只是代表一种价值。如果你有十七个
goats独角兽,那么无论你选择以什么基数写下来,你仍然拥有相同数量的独角兽。一旦你决定使用人类可读的表示形式打印一个值,那么你必须选择一个基地。您的要求是用户希望看到以 10 为基数表示的 PID。
Numbers themselves don't have a base. They just represent a value. If you have seventeen
goatsunicorns, then you still have the same number of unicorns no matter what base you choose to write that down in.Once you decide to print a value using a human readable representation, then you have to choose a base. Your requirement is that the user expects to see the PID in a base 10 representation.
当然,它们是[由系统实用程序以 10 为基数打印的]。
Of course, they are [printed in base 10 by system utilities].