10b5d6b81SPeter Holm#!/bin/sh 20b5d6b81SPeter Holm 30b5d6b81SPeter Holm# 4*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 50b5d6b81SPeter Holm# 60b5d6b81SPeter Holm# Copyright (c) 2021 Peter Holm 70b5d6b81SPeter Holm# 80b5d6b81SPeter Holm# Redistribution and use in source and binary forms, with or without 90b5d6b81SPeter Holm# modification, are permitted provided that the following conditions 100b5d6b81SPeter Holm# are met: 110b5d6b81SPeter Holm# 1. Redistributions of source code must retain the above copyright 120b5d6b81SPeter Holm# notice, this list of conditions and the following disclaimer. 130b5d6b81SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 140b5d6b81SPeter Holm# notice, this list of conditions and the following disclaimer in the 150b5d6b81SPeter Holm# documentation and/or other materials provided with the distribution. 160b5d6b81SPeter Holm# 170b5d6b81SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 180b5d6b81SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 190b5d6b81SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 200b5d6b81SPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 210b5d6b81SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 220b5d6b81SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 230b5d6b81SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 240b5d6b81SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 250b5d6b81SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 260b5d6b81SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 270b5d6b81SPeter Holm# SUCH DAMAGE. 280b5d6b81SPeter Holm# 290b5d6b81SPeter Holm 300b5d6b81SPeter Holm# Trace random cc, c++ or make threads from a buildkernel 310b5d6b81SPeter Holm# Test scenario idea by kib@ 320b5d6b81SPeter Holm 330b5d6b81SPeter Holmold=`sysctl -in kern.kill_on_debugger_exit` 340b5d6b81SPeter Holm[ -z "$old" ] && exit 0 350b5d6b81SPeter Holmtrap "sysctl kern.kill_on_debugger_exit=$old" EXIT INT 360b5d6b81SPeter Holm 370b5d6b81SPeter Holm# Enable ptrace(2)d processes to continue 380b5d6b81SPeter Holmsysctl kern.kill_on_debugger_exit=0 390b5d6b81SPeter Holm./buildkernel.sh & kpid=$! 400b5d6b81SPeter Holmwhile true; do 410b5d6b81SPeter Holm for i in `jot 8`; do 420b5d6b81SPeter Holm rpid=`ps -l | grep -vwE 'grep|RE|defunct' | \ 430b5d6b81SPeter Holm grep -E "(cc|c\+\+|make) " | \ 440b5d6b81SPeter Holm sort -R | head -1 | awk '{print $2}'` 450b5d6b81SPeter Holm [ -n "$rpid" ] && break 460b5d6b81SPeter Holm sleep 1 470b5d6b81SPeter Holm done 480b5d6b81SPeter Holm [ -z "$rpid" ] && break 490b5d6b81SPeter Holm kill -0 $rpid 2>/dev/null || continue 500b5d6b81SPeter Holm ps -lp $rpid | tail -1 510b5d6b81SPeter Holm echo "truss -f -o /dev/null -p $rpid" 520b5d6b81SPeter Holm truss -f -o /dev/null -p $rpid & tpid=$! 530b5d6b81SPeter Holm sleep `jot -r 1 5 10` 540b5d6b81SPeter Holm pkill -9 truss 550b5d6b81SPeter Holm wait $tpid 560b5d6b81SPeter Holmdone 570b5d6b81SPeter Holmwait $kpid 580b5d6b81SPeter Holmexit $? 59