Skip to content

Commit

Permalink
Fix UNKNOWN(Zombie) Process in unexpected processes check
Browse files Browse the repository at this point in the history
  • Loading branch information
nagworld9 committed Aug 5, 2022
1 parent 1f84bac commit 0639c30
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions azurelinuxagent/common/cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,9 @@ def _check_processes_in_agent_cgroup(self):
current = process
while current != 0 and current not in agent_commands:
current = self._get_parent(current)
# Process started by agent will have a marker and check if that marker found in process environment.
if current == 0 and not self.__is_process_descendant_of_the_agent(process):
# Verify if Process started by agent based on the marker found in process environment or process is in Zombie state.
# If so, consider it as valid process in agent cgroup.
if current == 0 and not (self.__is_process_descendant_of_the_agent(process) or self.__is_zombie_process(process)):
unexpected.append(self.__format_process(process))
if len(unexpected) >= 5: # collect just a small sample
break
Expand Down Expand Up @@ -704,6 +705,23 @@ def __is_process_descendant_of_the_agent(pid):
pass
return False

@staticmethod
def __is_zombie_process(pid):
"""
Returns True if process is in Zombie state otherwise False.
Ex: cat /proc/18171/stat
18171 (python3) S 18103 18103 18103 0 -1 4194624 57736 64902 0 3
"""
try:
stat = '/proc/{0}/stat'.format(pid)
if os.path.exists(stat):
with open(stat, "r") as stat_file:
return stat_file.read().split()[2] == 'Z'
except Exception:
pass
return False

@staticmethod
def _check_agent_throttled_time(cgroup_metrics):
for metric in cgroup_metrics:
Expand Down

0 comments on commit 0639c30

Please sign in to comment.