英文:
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 (
"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
}
}
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 > /proc/sys/kernel/core_pattern
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论