我需要将系统生成的每个核心文件严格绑定到崩溃应用程序的某个bin版本。我可以在sysctl.conf中指定core-name模式:kernel.core_pattern,但是没有办法在这里放置bin版本。核心转储:如何确定崩溃应用程序的版本
如何将崩溃程序的版本放入核心文件(版本号)或其他任何方式来确定崩溃的bin的版本?
我需要将系统生成的每个核心文件严格绑定到崩溃应用程序的某个bin版本。我可以在sysctl.conf中指定core-name模式:kernel.core_pattern,但是没有办法在这里放置bin版本。核心转储:如何确定崩溃应用程序的版本
如何将崩溃程序的版本放入核心文件(版本号)或其他任何方式来确定崩溃的bin的版本?
我在.pro文件中使用了qmake VERSION变量,它包含SVN的版本号。它由QCoreApplication :: applicationVersion()提供,在我的每个bin中都通过flag --version。
假设你的应用程序可以得到远远不够,打印出它的版本号没有核心转储,你可以写一个小程序(蟒蛇很可能是最简单的)是由一个核心转储调用。该程序将读取标准输入,将其转储到文件,然后根据版本号重命名该文件。
从人5个核心:
Piping core dumps to a program Since kernel 2.6.19, Linux supports an alternate syntax for the /proc/sys/kernel/core_pattern file. If the first character of this file is a pipe symbol (|), then the remainder of the line is inter‐ preted as a program to be executed. Instead of being written to a disk file, the core dump is given as standard input to the program. Note the following points: * The program must be specified using an absolute pathname (or a path‐ name relative to the root directory, /), and must immediately follow the '|' character. * The process created to run the program runs as user and group root. * Command-line arguments can be supplied to the program (since Linux 2.6.24), delimited by white space (up to a total line length of 128 bytes). * The command-line arguments can include any of the % specifiers listed above. For example, to pass the PID of the process that is being dumped, specify %p in an argument.
如果你打电话给你的脚本在/ usr/local/bin目录/自卸车,然后
echo "| /usr/local/bin/dumper %E" > /proc/sys/kernel/core_pattern
的防振应标准输入复制到文件中,然后尝试运行命令行上命名的程序来提取版本号并使用它来重命名该文件。
像这样的东西可能工作(我还没有尝试过,所以在极端风险:)使用
#!/usr/bin/python
import sys,os,subprocess
from subprocess import check_output
CORE_FNAME="/tmp/core"
with open(CORE_FNAME,"f") as f:
while buf=sys.stdin.read(10000):
f.write(buf)
pname=sys.argv[1].replace('!','/')
out=subprocess.check_output([pname, "--version"])
version=out.split('\n')[0].split()[-1]
os.rename(CORE_FNAME, CORE_FNAME+version)
这样做是递归的核心转储,可能造成系统崩溃的真正的大风险。一定要使用ulimit来允许进程中的核心转储,这些进程可以在没有核心转储的情况下打印出自己的版本。
如果是您期望的程序,将脚本更改为重新运行该程序以获取版本信息仅限将是一个好主意。
bin版本究竟是什么?你是否在需要提取的可执行文件中的某个地方保留一些变量以获取版本号? – evaitl
我在.pro文件中使用了qmake VERSION变量,其中包含来自SVN的修订号。它由QCoreApplication :: applicationVersion()提供,在我的每个bin中都通过flag --version。 – portinary