# 错误：信号：被杀死

- **ID:** `go/os-exec-command-killed`
- **领域:** go
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

执行的命令被操作系统信号终止，通常为SIGKILL，由于资源限制或手动干预。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **Use exec.Cmd with SysProcAttr to set process group and handle signals** (85% 成功率)
   ```
   cmd := exec.Command("command")
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
if err := cmd.Run(); err != nil {
    if exitErr, ok := err.(*exec.ExitError); ok {
        if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
            if status.Signaled() { /* handle signal */ }
        }
    }
}
   ```

## 无效尝试

- **Restarting the command without investigating** — May be killed again due to same resource issue; check OOM killer or ulimit. (70% 失败率)
