make sure first call to running() after process exit returns false

This commit is contained in:
Johannes Hofmann
2016-12-03 14:07:08 +01:00
parent b453a8e616
commit 95188edf6f
2 changed files with 15 additions and 4 deletions

View File

@@ -965,10 +965,16 @@ elif not defined(useNimRtl):
var ret : int
var status : cint = 1
ret = waitpid(p.id, status, WNOHANG)
if ret == int(p.id) and WIFEXITED(status):
p.exitStatus = status
if ret == 0: return true # Can't establish status. Assume running.
result = ret == int(p.id)
if ret == int(p.id):
if WIFEXITED(status):
p.exitStatus = status
return false
else:
return true
elif ret == 0:
return true # Can't establish status. Assume running.
else:
return false
proc terminate(p: Process) =
if kill(p.id, SIGTERM) != 0'i32:

View File

@@ -16,3 +16,8 @@ var running = true
while running:
running = running(p)
doAssert(waitForExit(p) == QuitFailure)
# make sure that first call to running() after process exit returns false
p = startProcess(filename, dir)
os.sleep(500)
doAssert(not running(p))