你可以在操作系统的文档或官方网站上找到退出状态码及其含义。

huangapple go评论89阅读模式
英文:

Where do I find exit status codes and their meanings?

问题

我正在为你翻译以下内容:

我正在观看关于Go语言并发的教程,在遇到竞争条件后,程序以状态码66退出。

  • 66实际上代表什么意思?
  • 这个状态码是从哪里来的?(如果没有标准化,我如何找到定义这个状态码的源文件?)

我了解你可以使用Exit包设置状态码:
https://pkg.go.dev/github.com/carlmjohnson/exitcode#Exit

我找到了这个关于Linux的资源,但它缺少3-125:
https://tldp.org/LDP/abs/html/exitcodes.html

英文:

I was watching a tutorial on concurrency in golang and after hitting a race condition the program exited with status code 66.

  • What does 66 actually mean?
  • Where does this come from? (If there's no standardization, how can I find the source file that defines this?)

I understand you can set the status code with the Exit pkg:
https://pkg.go.dev/github.com/carlmjohnson/exitcode#Exit

I found this resource for Linux, but it's missing 3-125
https://tldp.org/LDP/abs/html/exitcodes.html

答案1

得分: 1

退出代码没有通用的含义,它与所有Linux程序的退出代码没有共享的含义。

竞争检测器的文档页面指出,66退出代码只是Go开发人员选择的一个值,它足够“非标准”,以指示原因是竞争检测,并且您实际上可以通过GORACE环境变量进行更改:

$ GORACE="exitcode=42" go run -race my_racey_program.go
...
exit status 42

至于源代码,Go存储库包含一堆*.syso二进制文件,位于src/runtime/race/目录下(链接指向go1.18.4发布版本)。

src/runtime/race/race.go的开头处的注释中提到:

...
预构建的竞争时运行时位于race_GOOS_GOARCH.syso中。
从src/runtime/race.go直接调用运行时。

英文:

The exit code doesn't have a generic meaning -- not a meaning shared with the exit code of all linux programs.

The doc page for the race detector indicates that the 66 exit code is just a value the go developpers chose -- it is "non standard" enough to indicate that the cause was a race detection -- and that you can actually change it via the GORACE environment variable :

$ GORACE="exitcode=42" go run -race my_racey_program.go
...
exit status 42

As far as source code goes : the go repository contains a bunch of *.syso binary files under src/runtime/race/ (<- link to go1.18.4 posted),

and the comment at the beginning of src/runtime/race/race.go mentions :

> ...
> The prebuilt race runtime lives in race_GOOS_GOARCH.syso.
> Calls to the runtime are done directly from src/runtime/race.go.

huangapple
  • 本文由 发表于 2022年7月26日 08:56:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/73116728.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定