I've seen the usage of exit status 3 in several python scripts that restart processes. As far as I know the convention is only about 0 and "not 0" on Unix/Linux.
Is there a convention defining other values like 3.
At least in the old days, a return value of 1 generally meant a hard error and value 2 was usually reserved for problems with the command line arguments — it meant that the user had made an error, not the program. But beyond that: no, no convention; and even that slight convention was not universal. Like dashes in front of command-line arguments, which some versions of ps(1) let you omit, return codes were just convention. In general, read the docs (or the source!) to the script you're running and you then have to write error-code checking code to its specific meanings.
There is no convention for non-zero values, they are commonly used to communicate the reason for termination and it's up to each application to define the mapping of error code and reason. In the case you're linking to you can clearly see a few lines above the check for exit code 3 that it is used to indicate that the code has changed.
Ie in this case this will give the behaviour that the automatic restart is done as long as the reason to terminate was that the code changed and nothing else.
发布评论
评论(4)
至少在过去,返回值 1 通常意味着硬错误,而值 2 通常是为命令行参数问题而保留的 - 这意味着用户犯了错误,而不是程序犯了错误。但除此之外:不,没有惯例;即使是这个小小的约定也不是普遍的。就像命令行参数前面的破折号一样,某些版本的 ps(1) 允许您省略破折号,返回码只是约定。一般来说,阅读您正在运行的脚本的文档(或源代码!),然后您必须编写错误代码检查代码以了解其特定含义。
At least in the old days, a return value of 1 generally meant a hard error and value 2 was usually reserved for problems with the command line arguments — it meant that the user had made an error, not the program. But beyond that: no, no convention; and even that slight convention was not universal. Like dashes in front of command-line arguments, which some versions of ps(1) let you omit, return codes were just convention. In general, read the docs (or the source!) to the script you're running and you then have to write error-code checking code to its specific meanings.
对于非零值没有约定,它们通常用于传达终止原因,并且由每个应用程序定义错误代码和原因的映射。在您链接到的情况下,您可以清楚地看到退出代码 3 检查上方的几行,它用于指示代码已更改。
即,在这种情况下,只要终止的原因是代码更改而没有其他原因,就会给出自动重新启动的行为。
There is no convention for non-zero values, they are commonly used to communicate the reason for termination and it's up to each application to define the mapping of error code and reason. In the case you're linking to you can clearly see a few lines above the check for exit code 3 that it is used to indicate that the code has changed.
Ie in this case this will give the behaviour that the automatic restart is done as long as the reason to terminate was that the code changed and nothing else.
在这种情况下,还不清楚。如果开发人员还在的话,foret 的建议是我完全会做的。
高级 Bash 脚本指南列出了一些具有特殊含义的常见退出代码。
In this case, its unclear. foret's suggestion is one I would totally do if the developer is still around.
The Advanced Bash Scripting Guide lists some common exit codes with special meanings.
BSD 试图标准化退出代码,但它没有(还没有?)流行起来:
BSD tried to standardize exit codes, but it didn't (hasn't yet?) caught on:
sysexits3