82
+```
+
+#
+
+```shell
+
+ PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
+ 13784 seantyw+ 20 0 1226856 4568 1536 S 107.3 0.1 0:22.65 test.out
+ 2903 seantyw+ 20 0 11.1g 75580 45056 S 9.3 0.9 0:04.94 node
+ 2797 seantyw+ 20 0 11.3g 102748 47872 R 6.0 1.3 0:05.74 node
+ 3718 seantyw+ 20 0 31.3g 142516 55296 S 3.3 1.8 0:10.09 node
+```
+
+#
+
+```shell
+$ ls
+2504-03.xyz.md go.prof main.go Makefile test.out
+
+
+$ sudo apt update && sudo apt install graphviz
+
+
+$ go tool pprof -png go.prof
+Generating report in profile001.png
+```
+
+#
+
+```shell
+94 type NullStruct struct {
+95 Value int
+96 Field *NullStruct
+97 }
+
+
+121
+122 null := NullStruct{}
+123
+124 fmt.Printf("val: %d\n", null.Field.Value)
+125
+
+```
+
+#
+
+```shell
+$ ./test.out 2
+panic: runtime error: invalid memory address or nil pointer dereference
+[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4b7593]
+
+goroutine 1 [running]:
+main.main()
+ /home/seantywork/hack/linux/linuxyz/0xgo/fault/main.go:124 +0xb3
+
```
\ No newline at end of file
}
+type NullStruct struct {
+ Value int
+ Field *NullStruct
+}
+
func main() {
- go threadFunc()
+ argc := len(os.Args)
+
+ if argc != 2 {
+ fmt.Printf("feed case\n")
+ os.Exit(-1)
+ }
- go profiler(10)
+ if os.Args[1] == "1" {
- for {
+ go threadFunc()
+
+ go profiler(10)
+
+ for {
+
+ time.Sleep(time.Millisecond * 1000)
+
+ }
+
+ } else if os.Args[1] == "2" {
+
+ null := NullStruct{}
- time.Sleep(time.Millisecond * 1000)
+ fmt.Printf("val: %d\n", null.Field.Value)
}
```
-# 02
+#
```shell
-# 03
+#
```shell
(gdb) thread 2
43 val = val ^ 1;
```
-# 04
+#
```shell
(gdb) step
35 if(nanosleep(&request , &remaing) < 0){
```
-# 05
+#
```shell
```
-# 05
+#
```shell
```
-# 06
+#
```shell
#
```shell
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ulimit -c
+$ ulimit -c
0
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ulimit -c unlimited
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ulimit -c
+$ ulimit -c unlimited
+$ ulimit -c
unlimited
```
#
```shell
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ./test.out 2
+$ ./test.out 2
Segmentation fault (core dumped)
```
#
```shell
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ls
+$ ls
2504-03.xyz.md core main.c Makefile test.out
```