waitForProcessExit waits for the process to exit or times out after the specified duration
(pid int, timeout time.Duration, logger *zap.Logger)
| 948 | |
| 949 | // waitForProcessExit waits for the process to exit or times out after the specified duration |
| 950 | func 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 |
| 980 | func isProcessRunning(pid int) (bool, error) { |
no test coverage detected