Go GOTRACEBACK=crash with no core file

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

Go GOTRACEBACK=crash with no core file

问题

以下是翻译好的内容:

go version go1.8.3 darwin/amd64

ulimit -c unlimited
env GOTRACEBACK=crash ./testgotraceback.go
ls -al
没有生成核心文件。

testgotraceback.go 源代码文件

package main

import (
"fmt"
"time"
)

func saferoutine(c chan bool) {
for i := 0; i < 10; i++ {
fmt.Println("Count:", i)
time.Sleep(1 * time.Second)
}
c <- true
}
func panicgoroutine(c chan bool) {
time.Sleep(5 * time.Second)
panic("Panic, omg ...")
c <- true
}
func main() {
c := make(chan bool, 2)
go saferoutine(c)
go panicgoroutine(c)
for i := 0; i < 2; i++ {
<-c
}
}

我想使用核心文件来跟踪一些错误。但是使用GOTRACEBACK=crash命令后,我发现没有生成核心文件。我也尝试了使用golang1.7版本,但问题依然存在。所以,问题出在哪里?谢谢帮助。

英文:

go version go1.8.3 darwin/amd64

ulimit -c unlimited
env GOTRACEBACK=crash ./testgotraceback.go
ls -al 
no core file generated.

testgotraceback.go source file

package main

import (
	&quot;fmt&quot;
	&quot;time&quot;
)

func saferoutine(c chan bool) {
	for i := 0; i &lt; 10; i++ {
		fmt.Println(&quot;Count:&quot;, i)
		time.Sleep(1 * time.Second)
	}
	c &lt;- true
}
func panicgoroutine(c chan bool) {
	time.Sleep(5 * time.Second)
	panic(&quot;Panic, omg ...&quot;)
	c &lt;- true
}
func main() {
	c := make(chan bool, 2)
	go saferoutine(c)
	go panicgoroutine(c)
	for i := 0; i &lt; 2; i++ {
		&lt;-c
	}
}

I want to use core file to trace some error.But use the GOTRACEBACK=crash command,I find no core file.use golang1.7 as well.
so ,what's the problem?thanks for help.

答案1

得分: 2

如果你希望在程序运行的目录中创建一个核心转储文件,不仅需要使用ulimit和设置GOTRACEBACK,还需要在操作系统上更改设置,将core文件保存在当前目录中

假设你使用的是Linux系统,这是与发行版相关的。你需要找到相关的sysfs条目,并将core值保存到其中。例如,在Fedora上,核心模式的sysfs条目是/proc/sys/kernel/core_pattern,要设置操作系统将核心文件保存在当前目录中,你需要执行以下命令:

echo core > /proc/sys/kernel/core_pattern
英文:

If you are expecting a core dump file to be created in the directory where you program is being run, you not only need to use ulimit and set GOTRACEBACK but also change settings on your operating system to save core file in the current directory.

Assuming you are using Linux, this is distribution-specific. You need to find relevant sysfs entry and save core value to it. For example, a core pattern sysfs entry on Fedora is /proc/sys/kernel/core_pattern and to setup you OS to save core files in the current directory, you would need to execute:

echo core &gt; /proc/sys/kernel/core_pattern

huangapple
  • 本文由 发表于 2017年6月8日 16:08:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/44430117.html
匿名

发表评论

匿名网友

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

确定