#!/usr/bin/env bash set -euo pipefail pid="$1" target_soname="$2" echo "pid: $pid" echo "soname: $target_soname" lines=() IFS=' ' for line in $(cat /proc/$pid/maps); do region=${line%% *} region_file=/proc/$pid/map_files/$region if [[ -e $region_file ]]; then soname=$(objdump -p "$region_file" 2>/dev/null | grep SONAME ||:) if [[ $(echo "$soname" | awk '{print $2}') == $target_soname ]]; then lines+=($line) fi fi done rm "$target_soname" 2>/dev/null ||: for line in ${lines[@]}; do cat /proc/$pid/map_files/$(echo "$line" | awk '{print $1}') >> $target_soname done