diff --git a/shinigami/utils.py b/shinigami/utils.py index cce3166..d7a84b6 100755 --- a/shinigami/utils.py +++ b/shinigami/utils.py @@ -10,6 +10,8 @@ import asyncssh import pandas as pd +INIT_PROCESS_ID = 1 + def id_in_whitelist(id_value: int, whitelist: Collection[Union[int, Tuple[int, int]]]) -> bool: """Return whether an ID is in a list of ID values @@ -84,7 +86,7 @@ async def terminate_errant_processes( process_df = pd.read_fwf(StringIO(ps_return.stdout), widths=[11, 11, 11, 11, 500]) # Identify orphaned processes and filter them by the UID whitelist - orphaned = process_df[process_df.PPID == 1] + orphaned = process_df[process_df.PPID == INIT_PROCESS_ID] terminate = orphaned[orphaned['UID'].apply(id_in_whitelist, whitelist=uid_whitelist)] for _, row in terminate.iterrows(): logging.debug(f'[{node}] Marking for termination {dict(row)}') @@ -93,6 +95,6 @@ async def terminate_errant_processes( logging.info(f'[{node}] No orphans found') elif not debug: - proc_id_str = ','.join(terminate.PGID.astype(str)) + proc_id_str = ','.join(terminate.PGID.unique().astype(str)) logging.info(f"[{node}] Sending termination signal for process groups {proc_id_str}") - await conn.run(f"pkill --signal -9 --pgroup {proc_id_str}", check=True) + await conn.run(f"pkill --signal 9 --pgroup {proc_id_str}", check=True)