nix-helpers: 6ccda2cf9e94976b7a85847e9a17f2411c71d0c1

     1: # Provides a 'backtrace' command showing the process hierarchy of its caller
     2: { bash, mkBin, runCommand }:
     3: 
     4: mkBin {
     5:   name = "backtrace";
     6:   script = ''
     7:     #!${bash}/bin/bash
     8:     set -e
     9: 
    10:     [[ -z "$NOTRACE" ]] || exit 0
    11: 
    12:     [[ -d /proc ]] || {
    13:       echo "No /proc found (not on Linux?), skipping backtrace" 1>&2
    14:       exit 0
    15:     }
    16: 
    17:     echo "Begin Backtrace:"
    18: 
    19:     ID="$$"  # Current PID
    20:     while [[ "$ID" -gt 1 ]]  # Loop until we reach init
    21:     do
    22:       # Show this PID's
    23:       cat "/proc/$ID/cmdline" | tr '\0' ' '
    24:       echo
    25: 
    26:       # Get parent's PID
    27:       ID=$(grep PPid < "/proc/$ID/status" | cut -d ':' -f2  |
    28:                                             sed -e 's/\s//g')
    29:     done
    30: 
    31:     echo "End Backtrace"
    32:   '';
    33: }

Generated by git2html.