MCPcopy Create free account
hub / github.com/astercloud/aster / waitForProcessExit

Method waitForProcessExit

pkg/tools/builtin/killshell.go:269–291  ·  view source on GitHub ↗

waitForProcessExit 等待进程退出

(ctx context.Context, pid int, timeoutSeconds int, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

267
268// waitForProcessExit 等待进程退出
269func (t *KillShellTool) waitForProcessExit(ctx context.Context, pid int, timeoutSeconds int, tc *tools.ToolContext) int {
270 timeout := time.Duration(timeoutSeconds) * time.Second
271 startTime := time.Now()
272
273 for time.Since(startTime) < timeout {
274 if !t.isProcessRunning(ctx, pid, tc) {
275 // 进程已退出,获取退出码
276 waitCmd := fmt.Sprintf("wait %d 2>/dev/null; echo $?", pid)
277 if result, err := tc.Sandbox.Exec(ctx, waitCmd, nil); err == nil {
278 var exitCode int
279 _, _ = fmt.Sscanf(result.Stdout, "%d", &exitCode)
280 return exitCode
281 }
282 return 0 // 假设成功退出
283 }
284
285 // 短暂等待后重试
286 time.Sleep(100 * time.Millisecond)
287 }
288
289 // 超时,进程仍在运行
290 return -1
291}
292
293// getCleanupInfo 获取清理信息
294func (t *KillShellTool) getCleanupInfo(task *TaskInfo) map[string]any {

Callers 1

ExecuteMethod · 0.95

Calls 3

isProcessRunningMethod · 0.95
ExecMethod · 0.65
DurationMethod · 0.45

Tested by

no test coverage detected