我需要將系統生成的每個核心文件嚴格綁定到崩潰應用程序的某個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