How do I change the kernel template for a specific application only?
My application requires the main file to be generated in a specific template.
How can I do this without affecting other processes?
And how do you do this when / proc is read-only?
man core
tells us:
Resetting the underlying pipeline server to the program
Since kernel 2.6.19, Linux supports an alternative syntax for
/proc/sys/kernel/core_pattern
. If the first character of this file is a pipe character (|
), then the rest of the line is interpreted as executable. Instead of a disk file, the kernel dump is listed as standard input to the program.Pay attention to the following points:
The program must be specified using an absolute path (or root path, /) and it must immediately follow the '|' character 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 a space (up to a total line length of 128 bytes).
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 the argument.
You can put a script there like
| /path/to/myscript %p %s %c
You can determine which process is running 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 "execute the default task" for processes other than your own