MCPcopy
hub / github.com/keploy/keploy / waitForProcessExit

Function waitForProcessExit

utils/utils.go:950–977  ·  view source on GitHub ↗

waitForProcessExit waits for the process to exit or times out after the specified duration

(pid int, timeout time.Duration, logger *zap.Logger)

Source from the content-addressed store, hash-verified

948
949// waitForProcessExit waits for the process to exit or times out after the specified duration
950func waitForProcessExit(pid int, timeout time.Duration, logger *zap.Logger) error {
951 // Create a timeout channel
952 timeoutCh := time.After(timeout)
953
954 // Loop to check if the process is running
955 for {
956 select {
957 case <-timeoutCh:
958 // If the timeout is reached, log the timeout and break
959 logger.Debug("Timed out waiting for process to exit", zap.Int("pid", pid))
960 return nil
961 default:
962 // Check if the process is running
963 isRunning, err := isProcessRunning(pid)
964 if err != nil {
965 return err
966 }
967
968 if !isRunning {
969 logger.Debug("Process exited", zap.Int("pid", pid))
970 return nil
971 }
972
973 // Wait for 1 second before checking again
974 time.Sleep(300 * time.Millisecond)
975 }
976 }
977}
978
979// isProcessRunning checks if a particular process is still running using os.FindProcess
980func isProcessRunning(pid int) (bool, error) {

Callers 1

InterruptProcessTreeFunction · 0.85

Calls 2

isProcessRunningFunction · 0.85
DebugMethod · 0.65

Tested by

no test coverage detected