Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Avoid waiting for zombie processes in synctl stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Quah committed Dec 2, 2021
1 parent a6f1a3a commit 7009f45
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions synctl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,24 @@ NORMAL = "\x1b[m"
def pid_running(pid):
try:
os.kill(pid, 0)
return True
except OSError as err:
if err.errno == errno.EPERM:
return True
return False
pass # process exists
else:
return False

# When running in a container, orphan processes may not get reaped and their
# PIDs may remain valid. Try to work around the issue.
try:
with open(f"/proc/{pid}/status") as status_file:
if "zombie" in status_file.read():
return False
except Exception:
# This isn't Linux or `/proc/` is unavailable.
# Assume that the process is still running.
pass

return True


def write(message, colour=NORMAL, stream=sys.stdout):
Expand Down

0 comments on commit 7009f45

Please sign in to comment.