正在运行的bash脚本在某处挂起。我可以找出它是什么线? [英] A running bash script is hung somewhere. Can I find out what line it is on?

查看:119
本文介绍了正在运行的bash脚本在某处挂起。我可以找出它是什么线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如。并在bash调试器支持连接到现有的流程和研究现状如何?

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

,也可以我很容易通过观察在/ proc bash的进程项发现的?是否有一个方便的工具给行号在活动的文件?

Or can I easily find out by looking at the bash process entries in /proc? Is there a convenient tool to give line numbers in active files?

我不希望有杀死并重新启动进程。

I don't want to have to kill and restart the process.

这是在Linux - Ubuntu的10.04

This is on Linux - Ubuntu 10.04.

推荐答案

最近,我发现自己在一个类似的立场。我有一个shell脚本,不通过其他身份标记(如参数等)

I recently found myself in a similar position. I had a shell script that was not identifiable through other means (such as arguments, etc.)

有办法找出更多关于比你所期望的正在运行的进程。

There are ways to find out a lot more about a running process than you would expect.

使用 lsof的-p $ PID 来查看哪些文件是开放的,这可能会给你一些线索。请注意,某些文件,而已删除,仍然可以由脚本保持打开。只要脚本不关闭文件,它仍然可以读取和写 - 和文件仍然占据了房间里的文件系统上。

Use lsof -p $pid to see what files are open, which may give you some clues. Note that some files, while "deleted", can still be kept open by the script. As long as the script doesn't close the file, it can still read and write from it - and the file still takes up room on the file system.

使用 strace的积极跟踪脚本使用系统调用。该脚本将读取脚本文件,所以你可以看到一些命令,因为他们在执行之前阅读。查找用这个命令的命令:

Use strace to actively trace the system calls used by the script. The script will read the script file, so you can see some of the commands as they are read prior to execution. Look for read commands with this command:

strace -p $pid -s 1024

这使得命令打印字符串长度最多为1024个字符(通常情况下, strace的命令将截断字符串比短得多)。

This makes the commands print strings up to 1024 characters long (normally, the strace command would truncate strings much shorter than that).

检查,以查看该脚本的详细信息目录的/ proc / $ PID ;特别注意事项,请参阅的/ proc / $ PID / ENVIRON ,这将给你用null分隔的过程环境。要阅读此文件正确,使用此命令:

Examine the directory /proc/$pid in order to see details about the script; in particular note, see /proc/$pid/environ which will give you the process environment separated by nulls. To read this "file" properly, use this command:

xargs -0 -i{} < /proc/$pid/environ

您可以通过管道将进入或将其保存在一个文件中。还有的/ proc / $ PID / CMDLINE ,但很可能只会给你的shell名( -bash 的实例)。

You can pipe that into less or save it in a file. There is also /proc/$pid/cmdline but it is possible that that will only give you the shell name (-bash for instance).

这篇关于正在运行的bash脚本在某处挂起。我可以找出它是什么线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆