今天在linux上写算法作业,矩阵连乘的最优解,看了很长一段时间了,勉强写的出来了,但还是有点不清晰,不得不承认是一只菜鸡。
这不是重点。之前在写的算法题用的都是纯c,一是开始只会用gcc编译,而是对c++没怎么接触过,有些望而生畏,包括c也是,能不用指针,就不用指针。
今天实在是受不了了,眼看着printf,scanf又臭又长,cout,cin又短又快,咬牙上吧,查了下资料,用g++编译链接即可,也是很方便。
g++ source.c -o executable
编译成功,运行报 segmention fault(core dump)
core dump 也叫核心转储,是在程序崩溃时产生的内存进程信息。
按道理应该在程序运行目录产生,ls-al 并未查看到,继续google
ulimit -a
查看, core file size 属性是否为0,若为0的话,代表系统默认不会产生core dump文件。
ulimit -c unlimited
可以设置 core file size 为无限。
一番操作下来,依然没有core dump 踪迹。
祭出神器Archwiki。
不出所料。
Examining a core dump
Use coredumpctl to find the corresponding dump:
coredumpctl list
You need to uniquely identify the relevant dump. This is possible by specifying a PID, name of the executable, path to the executable or a journalctl predicate (see coredumpctl(1) and journalctl(1) for details). To see details of the core dumps:
match 可以是 pid 也可以是可执行程序名
coredumpctl info match
Pay attention to “Signal” row, that helps to identify crash cause. For deeper analysis you can examine the backtrace using gdb:
coredumpctl gdb match
When gdb is started, use the bt command to print the backtrace:
(gdb) bt
一套组合下来,错误一目了然,发生在一个递归函数里,重复的使用了一块内存。