以下辅助函数预留用于未来的功能增强 当前实现使用taskManager,但这些函数提供了独立的底层操作能力 isProcessRunning 检查进程是否运行
(ctx context.Context, pid int, tc *tools.ToolContext)
| 225 | |
| 226 | // isProcessRunning 检查进程是否运行 |
| 227 | func (t *KillShellTool) isProcessRunning(ctx context.Context, pid int, tc *tools.ToolContext) bool { |
| 228 | if pid <= 0 { |
| 229 | return false |
| 230 | } |
| 231 | |
| 232 | // 使用ps命令检查进程 |
| 233 | psCmd := fmt.Sprintf("ps -p %d > /dev/null 2>&1", pid) |
| 234 | result, err := tc.Sandbox.Exec(ctx, psCmd, nil) |
| 235 | if err != nil { |
| 236 | return false |
| 237 | } |
| 238 | |
| 239 | return result.Code == 0 |
| 240 | } |
| 241 | |
| 242 | // getSignalNumber 获取信号编号 |
| 243 | func (t *KillShellTool) getSignalNumber(signal string) int { |
no test coverage detected