Skip to content

Instantly share code, notes, and snippets.

@dpsmith
Created April 5, 2016 22:20
Show Gist options
  • Select an option

  • Save dpsmith/3abe1b6d018b39b629b80cb7c79425d0 to your computer and use it in GitHub Desktop.

Select an option

Save dpsmith/3abe1b6d018b39b629b80cb7c79425d0 to your computer and use it in GitHub Desktop.
Debug a daemon that forks(clone) using strace
#!/bin/bash
self=$0
pid=$1
while read line; do
echo $line >> ${pid}.log
if $(echo $line | grep -q -e '^clone'); then
child=$(echo $line|awk '{ print $5 }')
echo "Parent: $pid" > ${child}.log
if [[ -n $child ]]; then
echo "$pid spawned: $child"
( $self $child )&
fi
fi
done < <(strace -s 16384 -p $pid 2>&1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment