Skip to content

Commit

Permalink
Fix 'NoSuchProcess' exception in process_checker (sonic-net#5716)
Browse files Browse the repository at this point in the history
The psutil library used in process_checker create a cache for each
process when calling process_iter. So, there is some possibility that
one process exists when calling process_iter, but not exists when
calling cmdline, which will raise a NoSuchProcess exception. This commit
fix the issue.

Signed-off-by: bingwang <bingwang@microsoft.com>
  • Loading branch information
bingwang-ms authored and santhosh-kt committed Feb 25, 2021
1 parent 83e6e11 commit 628c494
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions files/image_config/monit/process_checker
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ def check_process_existence(container_name, process_cmdline):
# state, then it will be marked as 'running'.
is_running = False
for process in psutil.process_iter(["cmdline", "status"]):
if ((' '.join(process.cmdline())).startswith(process_cmdline) and process.status() in ["running", "sleeping"]):
is_running = True
break
try:
if ((' '.join(process.cmdline())).startswith(process_cmdline) and process.status() in ["running", "sleeping"]):
is_running = True
break
except psutil.NoSuchProcess:
pass

if not is_running:
# If this script is run by Monit, then the following output will be appended to
Expand Down

0 comments on commit 628c494

Please sign in to comment.