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

后端 未结 3 1781
北恋
北恋 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:57

    Use pstree to show what linux command/executable your script is calling. For example, 21156 is the pid of my hanging script:

    ocfs2cts1:~ # pstree -pl 21156
    activate_discon(21156)───mpirun(15146)─┬─fillup_contig_b(15149)───sudo(15231)───chmod(15232)
                                           ├─ssh(15148)
                                           └─{mpirun}(15147)
    

    So that, I know it's hanging at chmod command. Then, show the stack trace by:

    ocfs2cts1:~ # cat /proc/15232/stack 
    [] __ocfs2_cluster_lock.isra.39+0x1bf/0x620 [ocfs2]
    [] ocfs2_inode_lock_full_nested+0x12d/0x840 [ocfs2]
    [] ocfs2_inode_lock_atime+0xcb/0x170 [ocfs2]
    [] ocfs2_readdir+0x41/0x1b0 [ocfs2]
    [] iterate_dir+0x9c/0x110
    [] SyS_getdents+0x83/0xf0
    [] entry_SYSCALL_64_fastpath+0x12/0x6d
    [] 0xffffffffffffffff
    

    Oh, boy, it's likely a deadlock bug...

提交回复
热议问题