Skip to content

Instantly share code, notes, and snippets.

@motebaya
Last active May 29, 2024 12:44
Show Gist options
  • Save motebaya/f27c0969d71e28caa034cf9c2455e1d4 to your computer and use it in GitHub Desktop.
Save motebaya/f27c0969d71e28caa034cf9c2455e1d4 to your computer and use it in GitHub Desktop.
Tracking PID based on the program name being executed by php7.4 and give it into GDB
#!/usr/bin/bash
track_pid() {
ps_output=$(ps aux | grep programname | head -1)
while IFS= read -r line; do
if [[ $line == *"php7.4"* ]]; then
pid=$(echo "$line" | awk '{print $2}')
echo "[OK] Found PHP process with PID: $pid"
# sleep 1
gdb -p "$pid" -x "command.txt"
return 0
# exit 0
fi
done <<<"$ps_output"
return 1
}
while true; do
if track_pid; then
echo "ok found"
break
fi
echo "$(date +[%H:%M:%S]) Tracking PID...."
sleep 0.5
done
@motebaya
Copy link
Author

command.txt, whatever e.g dump core:

generate-core-file
detach
quit

custom: "php7.4" with another runtime,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment