A running bash script is hung somewhere. Can I find out what line it is on?

后端 未结 3 1817
北恋
北恋 2021-02-04 06:24

E.g. does the bash debugger support attaching to existing processes and examining the current state?

Or can I easily find out by looking at the bash process entries in /

3条回答
  •  时光取名叫无心
    2021-02-04 06:40

    No real solution. But in most cases a script is waiting for a child process to terminate:

    ps --ppid  $(pidof yourscript)
    

    You could also setup signal handlers in you shell skript do toggle the printing of commands:

    #!/bin/bash
    
    trap "set -x" SIGUSR1
    trap "set +x" SIGUSR2
    
    while true; do
        sleep 1
    done
    

    Then use

    kill -USR1 $(pidof yourscript)
    kill -USR2 $(pidof yourscript)
    

提交回复
热议问题