Skip to content

Commit

Permalink
Send kill SIGSEGV if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-grz committed Jan 21, 2025
1 parent d9ee2d0 commit e874198
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 11 additions & 5 deletions nat-lab/bin/kill_process_by_natlab_id
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
#!/usr/bin/env bash

if [[ "$#" -ne 1 ]]; then
echo "Wrong number of parameters"
if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then
echo "Usage: $0 <NATLAB_ID> [--SEGV]"
exit 1
fi

NATLAB_ID=$1
SIGNAL="-TERM" # default SIGTERM

# If the second argument is '--SEGV', send SIGSEGV (-11) to create a coredump
if [[ "$2" == "--SEGV" ]]; then
SIGNAL="-SEGV"
fi

for pid in $(ps -e -o pid=); do
if grep --null-data --text KILL_ID=${NATLAB_ID} /proc/${pid}/environ; then
cmd=$(tr -d '\000' < /proc/${pid}/cmdline || echo "N/A")
echo "$(date) Killing ${pid} ${cmd}"
kill "${pid}"
echo "$(date) Killing ${pid} ${cmd} with signal: $SIGNAL"
kill "${SIGNAL}" "${pid}"
wait "${pid}" 2>/dev/null
exit 0
fi
done

echo "The process to kill not found"
echo "The process to kill was not found: $NATLAB_ID"
5 changes: 3 additions & 2 deletions nat-lab/tests/utils/tcpdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from asyncio import Event, wait_for, sleep
from config import WINDUMP_BINARY_WINDOWS
from contextlib import asynccontextmanager, AsyncExitStack
from datetime import datetime
from typing import AsyncIterator, Optional
from utils.connection import TargetOS, Connection
from utils.output_notifier import OutputNotifier
Expand Down Expand Up @@ -137,11 +138,11 @@ async def run(self) -> AsyncIterator["TcpDump"]:
try:
await wait_for(self.start_event.wait(), 0)
except TimeoutError as e:
print("tcpdump timed out, killing it to create a coredump 🗡️")
print(datetime.now() ,"tcpdump timed out, killing it to create a coredump 🗡️")
if self.connection.target_os != TargetOS.Windows:
if self.kill_id:
await self.connection.create_process(
["kill", "-11", str(self.kill_id)]
["/opt/bin/kill_process_by_natlab_id", str(self.kill_id), "--SEGV"]
).execute()
else:
await self.connection.create_process(
Expand Down

0 comments on commit e874198

Please sign in to comment.