xref: /freebsd/share/man/man5/core.5 (revision e7be843b4a162e68651d3911f0357ed464915629)
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.Dd July 17, 2025
29.Dt CORE 5
30.Os
31.Sh NAME
32.Nm core
33.Nd memory image file format
34.Sh SYNOPSIS
35.In sys/param.h
36.Sh DESCRIPTION
37A small number of signals which cause abnormal termination of a process
38also cause a record of the process's in-core state to be written
39to disk for later examination by one of the available debuggers.
40(See
41.Xr sigaction 2 . )
42This memory image is written to a file named by default
43.Nm programname.core
44in the working directory;
45provided the terminated process had write permission in the directory,
46and provided the abnormality did not cause
47a system crash.
48(In this event, the decision to save the core file is arbitrary, see
49.Xr savecore 8 . )
50.Pp
51The name of the file is controlled via the
52.Xr sysctl 8
53variable
54.Va kern.corefile .
55The contents of this variable describes a filename to store
56the core image to.
57This filename can be absolute, or relative (which
58will resolve to the current working directory of the program
59generating it).
60.Pp
61The following format specifiers may be used in the
62.Va kern.corefile
63sysctl to insert additional information into the resulting core
64filename:
65.Bl -tag -width "1234567890" -compact -offset "12345"
66.It Em \&%H
67Machine hostname.
68.It Em \&%I
69An index starting at zero until the sysctl
70.Em debug.ncores
71is reached.
72This can be useful for limiting the number of corefiles
73generated by a particular process.
74.It Em \&%N
75process name.
76.It Em \&%P
77processes PID.
78.It Em \&%S
79signal during core.
80.It Em \&%U
81process UID.
82.El
83.Pp
84The name defaults to
85.Em \&%N.core ,
86yielding the traditional
87.Fx
88behaviour.
89.Pp
90The maximum size of a core file is limited by the
91.Dv RLIMIT_CORE
92.Xr setrlimit 2
93limit.
94Files which would be larger than the limit are not created.
95.Pp
96With a large limit, a process that had mapped a very large,
97and perhaps sparsely populated, virtual memory region, could take
98a very long time to create core dumps.
99The system ignores all signals sent to a process writing a core file, except
100.Dv SIGKILL
101which terminates the writing and causes immediate exit of the process.
102The behavior of
103.Dv SIGKILL
104can be disabled by setting tunable
105.Xr sysctl 8
106variable
107.Va kern.core_dump_can_intr
108to zero.
109.Pp
110By default, a process that changes user or group credentials whether
111real or effective will not create a corefile.
112This behaviour can be
113changed to generate a core dump by setting the
114.Xr sysctl 8
115variable
116.Va kern.sugid_coredump
117to 1.
118.Pp
119Corefiles can be compressed by the kernel if one of the following items
120are included in the kernel configuration file:
121.Bl -tag -width "1234567890" -compact -offset "12345"
122.It options
123GZIO
124.It options
125ZSTDIO
126.El
127.Pp
128The following sysctl control core file compression:
129.Bl -tag -width "kern.compress_user_cores_level" -compact -offset "12345"
130.It Em kern.compress_user_cores
131Enable compression of user cores.
132A value of 1 configures
133.Xr gzip 1
134compression,
135and a value of 2 configures
136.Xr zstd 1
137compression.
138Compressed core files will have a suffix of
139.Ql .gz
140or
141.Ql .zst
142appended to their filenames depending on the selected format.
143.It Em kern.compress_user_cores_level
144Compression level.
145Defaults to 6.
146.El
147.Sh NOTES
148Corefiles are written with open file descriptor information as an ELF note.
149By default, file paths are packed to only use as much space as needed.
150However, file paths can change at any time, including during core dump,
151and this can result in truncated file descriptor data.
152.Pp
153All file descriptor information can be preserved by disabling packing.
154This potentially wastes up to PATH_MAX bytes per open fd.
155Packing is disabled with
156.Dl sysctl kern.coredump_pack_fileinfo=0 .
157.Pp
158Similarly, corefiles are written with vmmap information as an ELF note, which
159contains file paths.
160By default, they are packed to only use as much space as
161needed.
162By the same mechanism as for the open files note, these paths can also
163change at any time and result in a truncated note.
164.Pp
165All vmmap information can be preserved by disabling packing.
166Like the file information, this potentially wastes up to PATH_MAX bytes per
167mapped object.
168Packing is disabled with
169.Dl sysctl kern.coredump_pack_vmmapinfo=0 .
170.Sh EXAMPLES
171In order to store all core images in per-user private areas under
172.Pa /var/coredumps
173(assuming the appropriate subdirectories exist and are writable by users),
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 Pq Pa ports/devel/gdb ,
181.Xr gzip 1 ,
182.Xr kgdb 1 Pq Pa ports/devel/gdb ,
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