xref: /freebsd/share/man/man5/core.5 (revision 19477ee0d9bbd865a98a3a20f38f979b1825696c)
1afe61c15SRodney W. Grimes.\" Copyright (c) 1980, 1991, 1993
2afe61c15SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
3afe61c15SRodney W. Grimes.\"
4afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
5afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions
6afe61c15SRodney W. Grimes.\" are met:
7afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
8afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
9afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
10afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
11afe61c15SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
12dda5b397SEitan Adler.\" 3. Neither the name of the University nor the names of its contributors
13afe61c15SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
14afe61c15SRodney W. Grimes.\"    without specific prior written permission.
15afe61c15SRodney W. Grimes.\"
16afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19afe61c15SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26afe61c15SRodney W. Grimes.\" SUCH DAMAGE.
27afe61c15SRodney W. Grimes.\"
28afe61c15SRodney W. Grimes.\"     @(#)core.5	8.3 (Berkeley) 12/11/93
29afe61c15SRodney W. Grimes.\"
30*19477ee0SCeri Davies.Dd November 12, 2023
31afe61c15SRodney W. Grimes.Dt CORE 5
323d45e180SRuslan Ermilov.Os
33afe61c15SRodney W. Grimes.Sh NAME
34afe61c15SRodney W. Grimes.Nm core
35afe61c15SRodney W. Grimes.Nd memory image file format
36afe61c15SRodney W. Grimes.Sh SYNOPSIS
3732eef9aeSRuslan Ermilov.In sys/param.h
38afe61c15SRodney W. Grimes.Sh DESCRIPTION
39afe61c15SRodney W. GrimesA small number of signals which cause abnormal termination of a process
40afe61c15SRodney W. Grimesalso cause a record of the process's in-core state to be written
41afe61c15SRodney W. Grimesto disk for later examination by one of the available debuggers.
42afe61c15SRodney W. Grimes(See
43afe61c15SRodney W. Grimes.Xr sigaction 2 . )
44aa81f3a9SJoerg WunschThis memory image is written to a file named by default
45afe61c15SRodney W. Grimes.Nm programname.core
46afe61c15SRodney W. Grimesin the working directory;
47afe61c15SRodney W. Grimesprovided the terminated process had write permission in the directory,
48afe61c15SRodney W. Grimesand provided the abnormality did not cause
49afe61c15SRodney W. Grimesa system crash.
50afe61c15SRodney W. Grimes(In this event, the decision to save the core file is arbitrary, see
51afe61c15SRodney W. Grimes.Xr savecore 8 . )
52afe61c15SRodney W. Grimes.Pp
532ec505d2SKonstantin BelousovThe maximum size of a core file is limited by the
542ec505d2SKonstantin Belousov.Dv RLIMIT_CORE
552ec505d2SKonstantin Belousov.Xr setrlimit 2
562ec505d2SKonstantin Belousovlimit.
57afe61c15SRodney W. GrimesFiles which would be larger than the limit are not created.
58afe61c15SRodney W. Grimes.Pp
59b5cadc64SKonstantin BelousovWith a large limit, a process that had mapped a very large,
60b5cadc64SKonstantin Belousovand perhaps sparsely populated, virtual memory region, could take
61b5cadc64SKonstantin Belousova very long time to create core dumps.
62b5cadc64SKonstantin BelousovThe system ignores all signals sent to a process writing a core file, except
63b5cadc64SKonstantin Belousov.Dv SIGKILL
64b5cadc64SKonstantin Belousovwhich terminates the writing and causes immediate exit of the process.
65b5cadc64SKonstantin BelousovThe behavior of
66b5cadc64SKonstantin Belousov.Dv SIGKILL
67b5cadc64SKonstantin Belousovcan be disabled by setting tunable
68b5cadc64SKonstantin Belousov.Xr sysctl 8
69b5cadc64SKonstantin Belousovvariable
70b5cadc64SKonstantin Belousov.Va kern.core_dump_can_intr
71b5cadc64SKonstantin Belousovto zero.
72b5cadc64SKonstantin Belousov.Pp
73aa81f3a9SJoerg WunschThe name of the file is controlled via the
74aa81f3a9SJoerg Wunsch.Xr sysctl 8
75aa81f3a9SJoerg Wunschvariable
76aa81f3a9SJoerg Wunsch.Va kern.corefile .
77aa81f3a9SJoerg WunschThe contents of this variable describes a filename to store
780f3ac37eSRuslan Ermilovthe core image to.
790f3ac37eSRuslan ErmilovThis filename can be absolute, or relative (which
80aa81f3a9SJoerg Wunschwill resolve to the current working directory of the program
810f3ac37eSRuslan Ermilovgenerating it).
820dce12b8SAlfred Perlstein.Pp
830dce12b8SAlfred PerlsteinThe following format specifiers may be used in the
840dce12b8SAlfred Perlstein.Va kern.corefile
8578f57a9cSMark Johnstonsysctl to insert additional information into the resulting core
8678f57a9cSMark Johnstonfilename:
870dce12b8SAlfred Perlstein.Bl -tag -width "1234567890" -compact -offset "12345"
880dce12b8SAlfred Perlstein.It Em \&%H
890dce12b8SAlfred PerlsteinMachine hostname.
900dce12b8SAlfred Perlstein.It Em \&%I
910dce12b8SAlfred PerlsteinAn index starting at zero until the sysctl
92df4193e7SSergey Kandaurov.Em debug.ncores
93da9782daSSergey Kandaurovis reached.
94da9782daSSergey KandaurovThis can be useful for limiting the number of corefiles
950dce12b8SAlfred Perlsteingenerated by a particular process.
960dce12b8SAlfred Perlstein.It Em \&%N
970dce12b8SAlfred Perlsteinprocess name.
980dce12b8SAlfred Perlstein.It Em \&%P
990dce12b8SAlfred Perlsteinprocesses PID.
1009d3ecb7eSEric van Gyzen.It Em \&%S
1019d3ecb7eSEric van Gyzensignal during core.
1020dce12b8SAlfred Perlstein.It Em \&%U
1030dce12b8SAlfred Perlsteinprocess UID.
1040dce12b8SAlfred Perlstein.El
1050dce12b8SAlfred Perlstein.Pp
1060f3ac37eSRuslan ErmilovThe name defaults to
107aa81f3a9SJoerg Wunsch.Em \&%N.core ,
108b5c508fbSRuslan Ermilovyielding the traditional
109b5c508fbSRuslan Ermilov.Fx
110b5c508fbSRuslan Ermilovbehaviour.
111aa81f3a9SJoerg Wunsch.Pp
11253d3620bSNik ClaytonBy default, a process that changes user or group credentials whether
1130f3ac37eSRuslan Ermilovreal or effective will not create a corefile.
1140f3ac37eSRuslan ErmilovThis behaviour can be
11553d3620bSNik Claytonchanged to generate a core dump by setting the
11653d3620bSNik Clayton.Xr sysctl 8
11753d3620bSNik Claytonvariable
11853d3620bSNik Clayton.Va kern.sugid_coredump
11953d3620bSNik Claytonto 1.
1200dce12b8SAlfred Perlstein.Pp
121aa14e9b7SMark JohnstonCorefiles can be compressed by the kernel if the following item
122aa14e9b7SMark Johnstonis included in the kernel configuration file:
1230dce12b8SAlfred Perlstein.Bl -tag -width "1234567890" -compact -offset "12345"
1240dce12b8SAlfred Perlstein.It options
125aa14e9b7SMark JohnstonGZIO
1260dce12b8SAlfred Perlstein.El
1270dce12b8SAlfred Perlstein.Pp
12878f57a9cSMark JohnstonThe following sysctl control core file compression:
12978f57a9cSMark Johnston.Bl -tag -width "kern.compress_user_cores_level" -compact -offset "12345"
1300dce12b8SAlfred Perlstein.It Em kern.compress_user_cores
13178f57a9cSMark JohnstonEnable compression of user cores.
1326026dcd7SMark JohnstonA value of 1 configures
1336026dcd7SMark Johnston.Xr gzip 1
1346026dcd7SMark Johnstoncompression,
1356026dcd7SMark Johnstonand a value of 2 configures
1366026dcd7SMark Johnston.Xr zstd 1
1376026dcd7SMark Johnstoncompression.
1386026dcd7SMark JohnstonCompressed core files will have a suffix of
139aa14e9b7SMark Johnston.Ql .gz
1406026dcd7SMark Johnstonor
1416026dcd7SMark Johnston.Ql .zst
1426026dcd7SMark Johnstonappended to their filenames depending on the selected format.
14378f57a9cSMark Johnston.It Em kern.compress_user_cores_level
14478f57a9cSMark JohnstonCompression level.
14578f57a9cSMark JohnstonDefaults to 6.
1460dce12b8SAlfred Perlstein.El
14714bdbaf2SConrad Meyer.Sh NOTES
14814bdbaf2SConrad MeyerCorefiles are written with open file descriptor information as an ELF note.
14914bdbaf2SConrad MeyerBy default, file paths are packed to only use as much space as needed.
15014bdbaf2SConrad MeyerHowever, file paths can change at any time, including during core dump,
15114bdbaf2SConrad Meyerand this can result in truncated file descriptor data.
15214bdbaf2SConrad Meyer.Pp
15314bdbaf2SConrad MeyerAll file descriptor information can be preserved by disabling packing.
15414bdbaf2SConrad MeyerThis potentially wastes up to PATH_MAX bytes per open fd.
15514bdbaf2SConrad MeyerPacking is disabled with
15614bdbaf2SConrad Meyer.Dl sysctl kern.coredump_pack_fileinfo=0 .
157e6b95927SConrad Meyer.Pp
158e6b95927SConrad MeyerSimilarly, corefiles are written with vmmap information as an ELF note, which
159e6b95927SConrad Meyercontains file paths.
160e6b95927SConrad MeyerBy default, they are packed to only use as much space as
161e6b95927SConrad Meyerneeded.
162e6b95927SConrad MeyerBy the same mechanism as for the open files note, these paths can also
163e6b95927SConrad Meyerchange at any time and result in a truncated note.
164e6b95927SConrad Meyer.Pp
165e6b95927SConrad MeyerAll vmmap information can be preserved by disabling packing.
166e6b95927SConrad MeyerLike the file information, this potentially wastes up to PATH_MAX bytes per
167e6b95927SConrad Meyermapped object.
168e6b95927SConrad MeyerPacking is disabled with
169e6b95927SConrad Meyer.Dl sysctl kern.coredump_pack_vmmapinfo=0 .
170aa81f3a9SJoerg Wunsch.Sh EXAMPLES
171aa81f3a9SJoerg WunschIn order to store all core images in per-user private areas under
172*19477ee0SCeri Davies.Pa /var/coredumps
173*19477ee0SCeri Davies(assuming the appropriate subdirectories exist and are writable by users),
174aa81f3a9SJoerg Wunschthe following
175aa81f3a9SJoerg Wunsch.Xr sysctl 8
176aa81f3a9SJoerg Wunschcommand can be used:
177aa81f3a9SJoerg Wunsch.Pp
17807d6dffaSEdward Tomasz Napierala.Dl sysctl kern.corefile=/var/coredumps/\&%U/\&%N.core
179afe61c15SRodney W. Grimes.Sh SEE ALSO
1803c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb ,
18178f57a9cSMark Johnston.Xr gzip 1 ,
1824ee44ffcSJens Schweikhardt.Xr kgdb 1 Pq Pa ports/devel/gdb ,
183c69a537cSWolfram Schneider.Xr setrlimit 2 ,
184aa81f3a9SJoerg Wunsch.Xr sigaction 2 ,
185aa81f3a9SJoerg Wunsch.Xr sysctl 8
186afe61c15SRodney W. Grimes.Sh HISTORY
187afe61c15SRodney W. GrimesA
1884b66483fSRuslan Ermilov.Nm
189afe61c15SRodney W. Grimesfile format appeared in
190c7b00f00SMateusz Piotrowski.At v1 .
191