xref: /freebsd/share/man/man5/core.5 (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)core.5	8.3 (Berkeley) 12/11/93
29.\" $FreeBSD$
30.\"
31.Dd October 5, 2021
32.Dt CORE 5
33.Os
34.Sh NAME
35.Nm core
36.Nd memory image file format
37.Sh SYNOPSIS
38.In sys/param.h
39.Sh DESCRIPTION
40A small number of signals which cause abnormal termination of a process
41also cause a record of the process's in-core state to be written
42to disk for later examination by one of the available debuggers.
43(See
44.Xr sigaction 2 . )
45This memory image is written to a file named by default
46.Nm programname.core
47in the working directory;
48provided the terminated process had write permission in the directory,
49and provided the abnormality did not cause
50a system crash.
51(In this event, the decision to save the core file is arbitrary, see
52.Xr savecore 8 . )
53.Pp
54The maximum size of a core file is limited by the
55.Dv RLIMIT_CORE
56.Xr setrlimit 2
57limit.
58Files which would be larger than the limit are not created.
59.Pp
60With a large limit, a process that had mapped a very large,
61and perhaps sparsely populated, virtual memory region, could take
62a very long time to create core dumps.
63The system ignores all signals sent to a process writing a core file, except
64.Dv SIGKILL
65which terminates the writing and causes immediate exit of the process.
66The behavior of
67.Dv SIGKILL
68can be disabled by setting tunable
69.Xr sysctl 8
70variable
71.Va kern.core_dump_can_intr
72to zero.
73.Pp
74The name of the file is controlled via the
75.Xr sysctl 8
76variable
77.Va kern.corefile .
78The contents of this variable describes a filename to store
79the core image to.
80This filename can be absolute, or relative (which
81will resolve to the current working directory of the program
82generating it).
83.Pp
84The following format specifiers may be used in the
85.Va kern.corefile
86sysctl to insert additional information into the resulting core
87filename:
88.Bl -tag -width "1234567890" -compact -offset "12345"
89.It Em \&%H
90Machine hostname.
91.It Em \&%I
92An index starting at zero until the sysctl
93.Em debug.ncores
94is reached.
95This can be useful for limiting the number of corefiles
96generated by a particular process.
97.It Em \&%N
98process name.
99.It Em \&%P
100processes PID.
101.It Em \&%S
102signal during core.
103.It Em \&%U
104process UID.
105.El
106.Pp
107The name defaults to
108.Em \&%N.core ,
109yielding the traditional
110.Fx
111behaviour.
112.Pp
113By default, a process that changes user or group credentials whether
114real or effective will not create a corefile.
115This behaviour can be
116changed to generate a core dump by setting the
117.Xr sysctl 8
118variable
119.Va kern.sugid_coredump
120to 1.
121.Pp
122Corefiles can be compressed by the kernel if the following item
123is included in the kernel configuration file:
124.Bl -tag -width "1234567890" -compact -offset "12345"
125.It options
126GZIO
127.El
128.Pp
129The following sysctl control core file compression:
130.Bl -tag -width "kern.compress_user_cores_level" -compact -offset "12345"
131.It Em kern.compress_user_cores
132Enable compression of user cores.
133A value of 1 configures
134.Xr gzip 1
135compression,
136and a value of 2 configures
137.Xr zstd 1
138compression.
139Compressed core files will have a suffix of
140.Ql .gz
141or
142.Ql .zst
143appended to their filenames depending on the selected format.
144.It Em kern.compress_user_cores_level
145Compression level.
146Defaults to 6.
147.El
148.Sh NOTES
149Corefiles are written with open file descriptor information as an ELF note.
150By default, file paths are packed to only use as much space as needed.
151However, file paths can change at any time, including during core dump,
152and this can result in truncated file descriptor data.
153.Pp
154All file descriptor information can be preserved by disabling packing.
155This potentially wastes up to PATH_MAX bytes per open fd.
156Packing is disabled with
157.Dl sysctl kern.coredump_pack_fileinfo=0 .
158.Pp
159Similarly, corefiles are written with vmmap information as an ELF note, which
160contains file paths.
161By default, they are packed to only use as much space as
162needed.
163By the same mechanism as for the open files note, these paths can also
164change at any time and result in a truncated note.
165.Pp
166All vmmap information can be preserved by disabling packing.
167Like the file information, this potentially wastes up to PATH_MAX bytes per
168mapped object.
169Packing is disabled with
170.Dl sysctl kern.coredump_pack_vmmapinfo=0 .
171.Sh EXAMPLES
172In order to store all core images in per-user private areas under
173.Pa /var/coredumps ,
174the following
175.Xr sysctl 8
176command can be used:
177.Pp
178.Dl sysctl kern.corefile=/var/coredumps/\&%U/\&%N.core
179.Sh SEE ALSO
180.Xr gdb 1 ,
181.Xr gzip 1 ,
182.Xr kgdb 1 ,
183.Xr setrlimit 2 ,
184.Xr sigaction 2 ,
185.Xr sysctl 8
186.Sh HISTORY
187A
188.Nm
189file format appeared in
190.At v1 .
191