如何仅针对特定应用程序更改核心模式? [英] How to change core pattern only for a particular application?

查看:118
本文介绍了如何仅针对特定应用程序更改核心模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序要求以特定模式生成核心文件。

My application requires the core file to be generated in a specific pattern.

如何在不影响其他流程的情况下做到这一点?

How do I do this without affecting other processes?

当/ proc为只读时,该怎么办?

And how do I do this when /proc is read-only?

推荐答案

man核心告诉我们:


将核心转储到程序中

Piping core dumps to a program

从2.6.19内核开始,Linux支持
/ proc / sys / kernel / core_pattern 文件。如果此
文件的第一个字符是管道符号( | ),则该行的其余部分为
,解释为要执行的程序。核心转储不是写入
a磁盘文件,而是作为程序的标准输入提供。

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 interpreted 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.

请注意以下几点:


  • 必须使用绝对路径名(或相对于根目录/的
    路径名)指定程序,并且必须立即使用
    跟随'|'字符。

  • The program must be specified using an absolute pathname (or a pathname relative to the root directory, /), and must immediately follow the '|' character.

为运行该程序而创建的进程以用户和组
根用户身份运行。

The process created to run the program runs as user and group root.

可以向程序提供命令行参数(自Linux
2.6.24起),由空格分隔(最大行长为$ b $) b 128字节)。

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).

命令行参数可以包括上面列出的%%
中的任何一个。例如,要传递正在转储
的进程的PID,请在参数中指定%p。

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.

您可以在此处放置脚本,例如

You can put a script there, like e.g.

| /path/to/myscript %p %s %c

您可以检测到哪个进程正在触发coredump :(( man core ):

You can detect which process is triggering the coredump: (man core):

       %%  a single % character
       %p  PID of dumped process
       %u  (numeric) real UID of dumped process
       %g  (numeric) real GID of dumped process
       %s  number of signal causing dump
       %t  time of dump, expressed as seconds since the Epoch,  1970-01-01
           00:00:00 +0000 (UTC)
       %h  hostname (same as nodename returned by uname(2))
       %e  executable filename (without path prefix)
       %E  pathname of executable, with slashes ('/') replaced by exclama‐
           tion marks ('!').
       %c  core file size soft resource limit of crashing  process  (since
           Linux 2.6.24)

现在您要做的就是为您自己以外的其他进程做默认操作

Now all you have to do is "do the default thing" for other processes than your own

这篇关于如何仅针对特定应用程序更改核心模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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