mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
move examples to examples folder
This commit is contained in:
22
examples/anomaly-detection/lib/__init__.py
Normal file
22
examples/anomaly-detection/lib/__init__.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""
|
||||
Process Anomaly Detection - Constants and Utilities
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
MAX_SYSCALLS = 548
|
||||
|
||||
|
||||
def comm_for_pid(pid: int) -> bytes | None:
|
||||
"""Get process name from /proc."""
|
||||
try:
|
||||
with open(f"/proc/{pid}/comm", "rb") as f:
|
||||
return f.read().strip()
|
||||
except FileNotFoundError:
|
||||
logger.warning(f"Process with PID {pid} not found.")
|
||||
except PermissionError:
|
||||
logger.warning(f"Permission denied when accessing /proc/{pid}/comm.")
|
||||
except Exception as e:
|
||||
logger.warning(f"Error reading /proc/{pid}/comm: {e}")
|
||||
return None
|
||||
Reference in New Issue
Block a user