Getting an strace sample programmatically (non-interactively): dynamically attaching to a running process and detaching from it 10 seconds later. May be used to check if a process is hung, or what is it doing?
#!/bin/sh
…
rm -rf strace.out
strace -o strace.out -p $PID &
sleep 10
pkill -int strace # send SIGINT to strace process; this will make it detach, clean up, and exit.
STRACE_OUT=`cat $STRACE.OUT`
…