golang编译报错(go build command-line-arguments: signal: killed)
很简单的一段代码,go运行一个http服务:
package main
import (
"io"
"log"
"net/http"
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello, world!")
}
func main() {
http.HandleFunc("/hello", helloHandler)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.Error())
}
}
编译的时候系统日志(/var/log/message):
Mar 19 20:17:13 AY140118220542565584Z kernel: QThread invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0
Mar 19 20:17:13 AY140118220542565584Z kernel: QThread cpuset=/ mems_allowed=0
Mar 19 20:17:13 AY140118220542565584Z kernel: Pid: 1167, comm: QThread Not tainted 2.6.32-358.6.2.el6.x86_64 #1
Mar 19 20:17:13 AY140118220542565584Z kernel: Call Trace:
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff810cb5f1>] ? cpuset_print_task_mems_allowed+0x91/0xb0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8111cdf0>] ? dump_header+0x90/0x1b0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff810e92ce>] ? __delayacct_freepages_end+0x2e/0x30
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8121d1fc>] ? security_real_capable_noaudit+0x3c/0x70
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8111d272>] ? oom_kill_process+0x82/0x2a0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8111d1b1>] ? select_bad_process+0xe1/0x120
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8111d6b0>] ? out_of_memory+0x220/0x3c0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8112c35c>] ? __alloc_pages_nodemask+0x8ac/0x8d0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8116095a>] ? alloc_pages_current+0xaa/0x110
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8111a1d7>] ? __page_cache_alloc+0x87/0x90
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff81119bbe>] ? find_get_page+0x1e/0xa0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8111b197>] ? filemap_fault+0x1a7/0x500
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff81143194>] ? __do_fault+0x54/0x530
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff810aac2a>] ? futex_wait+0x21a/0x380
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff81143767>] ? handle_pte_fault+0xf7/0xb50
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff81063340>] ? wake_up_state+0x10/0x20
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff810a9b70>] ? wake_futex+0x40/0x60
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff810aa3ee>] ? futex_wake+0x10e/0x120
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff811443fa>] ? handle_mm_fault+0x23a/0x310
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff810474c9>] ? __do_page_fault+0x139/0x480
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8109be4f>] ? hrtimer_try_to_cancel+0x3f/0xd0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8109bf02>] ? hrtimer_cancel+0x22/0x30
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8150f663>] ? do_nanosleep+0x93/0xc0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff8100c2ee>] ? xen_hvm_callback_vector+0xe/0x20
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff815135ce>] ? do_page_fault+0x3e/0xa0
Mar 19 20:17:13 AY140118220542565584Z kernel: [<ffffffff81510985>] ? page_fault+0x25/0x30
Mar 19 20:17:13 AY140118220542565584Z kernel: Mem-Info:
Mar 19 20:17:13 AY140118220542565584Z kernel: Node 0 DMA per-cpu:
Mar 19 20:17:13 AY140118220542565584Z kernel: CPU 0: hi: 0, btch: 1 usd: 0
Mar 19 20:17:13 AY140118220542565584Z kernel: Node 0 DMA32 per-cpu:
Mar 19 20:17:13 AY140118220542565584Z kernel: CPU 0: hi: 186, btch: 31 usd: 30
Mar 19 20:17:13 AY140118220542565584Z kernel: active_anon:50750 inactive_anon:58844 isolated_anon:0
Mar 19 20:17:13 AY140118220542565584Z kernel: active_file:138 inactive_file:435 isolated_file:0
Mar 19 20:17:13 AY140118220542565584Z kernel: unevictable:0 dirty:10 writeback:0 unstable:0
Mar 19 20:17:13 AY140118220542565584Z kernel: free:1201 slab_reclaimable:2328 slab_unreclaimable:5683
Mar 19 20:17:13 AY140118220542565584Z kernel: mapped:133 shmem:25 pagetables:3450 bounce:0
Mar 19 20:17:13 AY140118220542565584Z kernel: Node 0 DMA free:2044kB min:84kB low:104kB high:124kB active_anon:6432kB inactive_anon:7208kB active_file:0kB inactive_file:12kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:15372kB mlocked:0kB dirty:0kB writeback:0kB mapped:0kB shmem:0kB slab_reclaimable:40kB slab_unreclaimable:0kB kernel_stack:0kB pagetables:24kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? no
Mar 19 20:17:13 AY140118220542565584Z kernel: lowmem_reserve[]: 0 489 489 489
Mar 19 20:17:13 AY140118220542565584Z kernel: Node 0 DMA32 free:2760kB min:2784kB low:3480kB high:4176kB active_anon:196568kB inactive_anon:228168kB active_file:552kB inactive_file:1728kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:500960kB mlocked:0kB dirty:40kB writeback:0kB mapped:532kB shmem:100kB slab_reclaimable:9272kB slab_unreclaimable:22732kB kernel_stack:1080kB pagetables:13776kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:1856 all_unreclaimable? no
Mar 19 20:17:13 AY140118220542565584Z kernel: lowmem_reserve[]: 0 0 0 0
Mar 19 20:17:13 AY140118220542565584Z kernel: Node 0 DMA: 1*4kB 1*8kB 1*16kB 1*32kB 1*64kB 1*128kB 1*256kB 1*512kB 1*1024kB 0*2048kB 0*4096kB = 2044kB
Mar 19 20:17:13 AY140118220542565584Z kernel: Node 0 DMA32: 26*4kB 32*8kB 22*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 1*2048kB 0*4096kB = 2760kB
Mar 19 20:17:13 AY140118220542565584Z kernel: 1219 total pagecache pages
Mar 19 20:17:13 AY140118220542565584Z kernel: 618 pages in swap cache
Mar 19 20:17:13 AY140118220542565584Z kernel: Swap cache stats: add 30005, delete 29387, find 14862/16277
Mar 19 20:17:13 AY140118220542565584Z kernel: Free swap = 1022960kB
Mar 19 20:17:13 AY140118220542565584Z kernel: Total swap = 1048568kB
Mar 19 20:17:13 AY140118220542565584Z kernel: 131071 pages RAM
Mar 19 20:17:13 AY140118220542565584Z kernel: 5902 pages reserved
Mar 19 20:17:13 AY140118220542565584Z kernel: 7776 pages shared
Mar 19 20:17:13 AY140118220542565584Z kernel: 119858 pages non-shared
Mar 19 20:17:13 AY140118220542565584Z kernel: [ pid ] uid tgid total_vm rss cpu oom_adj oom_score_adj name
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 279] 0 279 2714 0 0 -17 -1000 udevd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 520] 0 520 2713 0 0 -17 -1000 udevd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 819] 0 819 63877 104 0 0 0 rsyslogd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 835] 28 835 155468 80 0 0 0 nscd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 854] 0 854 118903 177 0 0 0 AliYunDunUpdate
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 884] 0 884 15508 24 0 -17 -1000 sshd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 892] 38 892 6760 47 0 0 0 ntpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 927] 0 927 27066 1 0 0 0 mysqld_safe
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1029] 27 1029 110387 790 0 0 0 mysqld
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1072] 0 1072 77555 459 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1080] 0 1080 28717 28 0 0 0 crond
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1093] 0 1093 1041 1 0 0 0 mingetty
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1095] 0 1095 1041 1 0 0 0 mingetty
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1096] 0 1096 2713 0 0 -17 -1000 udevd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1097] 48 1097 82549 5712 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1098] 48 1098 82609 5870 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1099] 48 1099 82481 5743 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1102] 48 1102 82609 5782 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1103] 48 1103 82613 5844 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1104] 48 1104 82483 5648 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1147] 0 1147 193866 505 0 0 0 AliYunDun
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 1163] 0 1163 196967 538 0 0 0 AliHids
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5064] 48 5064 84240 7574 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5065] 48 5065 82483 5772 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5066] 48 5066 82483 5758 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5067] 48 5067 82481 5743 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5068] 48 5068 84240 7422 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5069] 48 5069 82547 5853 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5070] 48 5070 82545 5713 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5071] 48 5071 82613 5904 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5072] 48 5072 82737 5947 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [ 5073] 48 5073 86742 9890 0 0 0 httpd
Mar 19 20:17:13 AY140118220542565584Z kernel: [22699] 0 22699 23487 230 0 0 0 sshd
Mar 19 20:17:13 AY140118220542565584Z kernel: [22701] 500 22701 23487 255 0 0 0 sshd
Mar 19 20:17:13 AY140118220542565584Z kernel: [22702] 500 22702 13292 189 0 0 0 sftp-server
Mar 19 20:17:13 AY140118220542565584Z kernel: [22714] 0 22714 23487 229 0 0 0 sshd
Mar 19 20:17:13 AY140118220542565584Z kernel: [22716] 500 22716 23487 241 0 0 0 sshd
Mar 19 20:17:13 AY140118220542565584Z kernel: [22717] 500 22717 27132 124 0 0 0 bash
Mar 19 20:17:13 AY140118220542565584Z kernel: [22774] 500 22774 27132 117 0 0 0 bash
Mar 19 20:17:13 AY140118220542565584Z kernel: [22798] 0 22798 42140 145 0 0 0 sudo
Mar 19 20:17:13 AY140118220542565584Z kernel: [22799] 0 22799 1040 22 0 0 0 scl
Mar 19 20:17:13 AY140118220542565584Z kernel: [22800] 0 22800 26540 49 0 0 0 bash
Mar 19 20:17:13 AY140118220542565584Z kernel: [22807] 0 22807 25260 28 0 0 0 tail
Mar 19 20:17:13 AY140118220542565584Z kernel: [22826] 500 22826 27132 116 0 0 0 bash
Mar 19 20:17:13 AY140118220542565584Z kernel: [22851] 500 22851 3782 80 0 0 0 top
Mar 19 20:17:13 AY140118220542565584Z kernel: [22861] 500 22861 50646 702 0 0 0 go
Mar 19 20:17:13 AY140118220542565584Z kernel: [22869] 500 22869 12066 11191 0 0 0 6l
Mar 19 20:17:13 AY140118220542565584Z kernel: Out of memory: Kill process 22869 (6l) score 28 or sacrifice child
Mar 19 20:17:13 AY140118220542565584Z kernel: Killed process 22869, UID 500, (6l) total-vm:48264kB, anon-rss:44604kB, file-rss:160kB
机器是Aliyun & CentOS 6.3 64bit & 512M & 1G swap,之前编译其他go代码的时候也发生过这种情况,但是我设置过swap文件之后就可以了。现在不知道怎么解决了。
低端机器连基本代码都不让编译了么555
一幽容翼一
9 years, 7 months ago
Answers
你这个是内存不够导致编译器失败吧,OOM有可能引起内核的crash,实际上你这个内核已经挂掉了。
ar 19 20:17:13 AY140118220542565584Z kernel: Call Trace:
Mar 19 20:17:13 AY140118220542565584Z kernel: [] ? cpuset_print_task_mems_allowed+0x91/0xb0
不过你不能本地编译过了,再传到服务器上吗?为什么要在服务器上直接编译?
golang对资源消耗还是挺高的,你这个即使编译过了,感觉运行时也有可能出现内存耗尽的情况。
建议:
1) free -m 看下剩余内存,如果swap都已经不够了,那肯定不行
2) 把一些占用资源的process,如果不是系统进程的话,就kill掉吧
生夏如花、
answered 9 years, 7 months ago