Skip to content

Commit

Permalink
Fix (PID Reaping): Ensure we don't wait unnecessarily on a zombie pro…
Browse files Browse the repository at this point in the history
…cess
  • Loading branch information
maleyva1 committed Jun 29, 2024
1 parent b9295c1 commit 887f4cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/pure/osproc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,7 @@ elif not defined(useNimRtl):
s.tv_sec = b.tv_sec
s.tv_nsec = b.tv_nsec

# Ensure we don't wait on an exited process
if not(p.running()) and p.exitFlag:
if p.exitFlag:
return exitStatusLikeShell(p.exitStatus)

if timeout == -1:
Expand Down Expand Up @@ -1417,6 +1416,8 @@ elif not defined(useNimRtl):
tmspec.tv_nsec = (timeout * 1_000_000)

try:
if not running(p):
return exitStatusLikeShell(p.exitStatus)
if clock_gettime(CLOCK_REALTIME, stspec) == -1:
raiseOSError(osLastError())
while true:
Expand Down
2 changes: 1 addition & 1 deletion tests/osproc/twaitforexit.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ block: # bug #5091
try:
discard waitForExit(p, msWait)
except OSError:
echo getCurrentExceptionMsg()
discard

# check that we don't have to wait msWait milliseconds
doAssert(getTime() < atStart + milliseconds(msWait))

0 comments on commit 887f4cc

Please sign in to comment.