#! /bin/sh linux_check_ptrace_scope() { if grep -q '1' . EOF stack_size=`ulimit -s` # Decrease stack size to 16k => smaller core files. # gcore won't run with the smaller stack ulimit -Ss 16 core_dump_filter=`cat /proc/self/coredump_filter` echo 0 > /proc/self/coredump_filter ./a.out & pid=$! echo $core_dump_filter > /proc/self/coredump_filter # Reset stack size as so there's enough space to run gcore. ulimit -s $stack_size echo "Sleeping for 5 seconds to wait for $pid" sleep 5 echo "Taking core from process $pid" gcore -o core $pid echo "Killing process $pid" kill -9 $pid