2008-06-12 04:59:28 +00:00
|
|
|
.\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
|
2006-03-31 07:05:11 +00:00
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
2008-03-18 14:47:54 +00:00
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2006-03-31 07:05:11 +00:00
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
2008-08-26 04:34:37 +00:00
|
|
|
.TH CORE 5 2008-08-26 "Linux" "Linux Programmer's Manual"
|
2006-03-31 07:05:11 +00:00
|
|
|
.SH NAME
|
|
|
|
core \- core dump file
|
|
|
|
.SH DESCRIPTION
|
2007-04-12 22:42:49 +00:00
|
|
|
The default action of certain signals is to cause a process to terminate
|
2006-03-31 07:05:11 +00:00
|
|
|
and produce a
|
|
|
|
.IR "core dump file" ,
|
2007-04-12 22:42:49 +00:00
|
|
|
a disk file containing an image of the process's memory at
|
2006-03-31 07:05:11 +00:00
|
|
|
the time of termination.
|
2008-08-26 04:34:37 +00:00
|
|
|
This image can be used in a debugger (e.g.,
|
|
|
|
.BR gdb (1))
|
|
|
|
to inspect the state of the program at the time that it terminated.
|
2006-03-31 07:05:11 +00:00
|
|
|
A list of the signals which cause a process to dump core can be found in
|
|
|
|
.BR signal (7).
|
|
|
|
|
2006-03-31 13:22:11 +00:00
|
|
|
A process can set its soft
|
2007-09-20 16:26:31 +00:00
|
|
|
.B RLIMIT_CORE
|
2007-04-12 22:42:49 +00:00
|
|
|
resource limit to place an upper limit on the size of the core dump file
|
2006-03-31 07:05:11 +00:00
|
|
|
that will be produced if it receives a "core dump" signal; see
|
|
|
|
.BR getrlimit (2)
|
|
|
|
for details.
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
There are various circumstances in which a core dump file is
|
2006-03-31 07:05:11 +00:00
|
|
|
not produced:
|
2008-01-01 07:55:02 +00:00
|
|
|
.IP * 3
|
2006-04-08 21:40:24 +00:00
|
|
|
The process does not have permission to write the core file.
|
2007-04-12 22:42:49 +00:00
|
|
|
(By default the core file is called
|
2006-04-08 21:40:24 +00:00
|
|
|
.IR core ,
|
2007-04-12 22:42:49 +00:00
|
|
|
and is created in the current working directory.
|
2006-04-08 21:40:24 +00:00
|
|
|
See below for details on naming.)
|
2007-04-12 22:42:49 +00:00
|
|
|
Writing the core file will fail if the directory in which
|
|
|
|
it is to be created is non-writable,
|
|
|
|
or if a file with the same name exists and
|
2006-04-08 21:40:24 +00:00
|
|
|
is not writable
|
2007-04-12 22:42:49 +00:00
|
|
|
or is not a regular file
|
2006-04-08 21:40:24 +00:00
|
|
|
(e.g., it is a directory or a symbolic link).
|
2008-01-01 07:55:02 +00:00
|
|
|
.IP *
|
2007-04-12 22:42:49 +00:00
|
|
|
A (writable, regular) file with the same name as would be used for the
|
|
|
|
core dump already exists, but there is more than one hard link to that
|
2006-11-25 01:45:17 +00:00
|
|
|
file.
|
|
|
|
.IP *
|
2007-04-12 22:42:49 +00:00
|
|
|
The file system where the core dump file would be created is full;
|
2008-03-19 11:52:55 +00:00
|
|
|
or has run out of inodes; or is mounted read-only;
|
2006-11-25 01:45:17 +00:00
|
|
|
or the user has reached their quota for the file system.
|
|
|
|
.IP *
|
2007-04-12 22:42:49 +00:00
|
|
|
The directory in which the core dump file is to be created does
|
2006-04-08 21:40:24 +00:00
|
|
|
not exist.
|
2006-03-31 07:05:11 +00:00
|
|
|
.IP *
|
2008-08-26 04:34:37 +00:00
|
|
|
The
|
2006-03-31 07:05:11 +00:00
|
|
|
.B RLIMIT_CORE
|
2008-08-26 04:34:37 +00:00
|
|
|
(core file size) or
|
2006-03-31 07:05:11 +00:00
|
|
|
.B RLIMIT_FSIZE
|
2008-08-26 04:34:37 +00:00
|
|
|
(file size) resource limits for the process are set to zero; see
|
|
|
|
.BR getrlimit (2)
|
|
|
|
and the documentation of the shell's
|
|
|
|
.I ulimit
|
|
|
|
command
|
|
|
|
.RI ( limit
|
|
|
|
in
|
|
|
|
.BR csh (1)).
|
2006-03-31 07:05:11 +00:00
|
|
|
.IP *
|
2007-04-12 22:42:49 +00:00
|
|
|
The binary being executed by the process does not have read
|
2006-03-31 07:05:11 +00:00
|
|
|
permission enabled.
|
|
|
|
.IP *
|
|
|
|
The process is executing a set-user-ID (set-group-ID) program
|
2007-04-12 22:42:49 +00:00
|
|
|
that is owned by a user (group) other than the real user (group)
|
2006-03-31 07:05:11 +00:00
|
|
|
ID of the process.
|
|
|
|
(However, see the description of the
|
|
|
|
.BR prctl (2)
|
|
|
|
.B PR_SET_DUMPABLE
|
|
|
|
operation, and the description of the
|
|
|
|
.I /proc/sys/fs/suid_dumpable
|
2008-07-01 02:09:18 +00:00
|
|
|
.\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
|
|
|
|
.\" and PR_SET_DUMPABLE to this page?
|
2006-03-31 07:05:11 +00:00
|
|
|
file in
|
|
|
|
.BR proc (5).)
|
|
|
|
.SS Naming of core dump files
|
2007-04-12 22:42:49 +00:00
|
|
|
By default, a core dump file is named
|
2006-03-31 07:05:11 +00:00
|
|
|
.IR core ,
|
2007-04-12 22:42:49 +00:00
|
|
|
but the
|
2006-03-31 07:05:11 +00:00
|
|
|
.I /proc/sys/kernel/core_pattern
|
2008-06-12 04:59:28 +00:00
|
|
|
file (since Linux 2.6 and 2.4.21)
|
2006-03-31 07:05:11 +00:00
|
|
|
can be set to define a template that is used to name core dump files.
|
|
|
|
The template can contain % specifiers which are substituted
|
|
|
|
by the following values when a core file is created:
|
2008-06-12 04:59:28 +00:00
|
|
|
.PP
|
|
|
|
.RS 4
|
|
|
|
.PD 0
|
|
|
|
.TP 4
|
|
|
|
%%
|
|
|
|
a single % character
|
|
|
|
.TP
|
|
|
|
%p
|
|
|
|
PID of dumped process
|
|
|
|
.TP
|
|
|
|
%u
|
|
|
|
(numeric) real UID of dumped process
|
|
|
|
.TP
|
|
|
|
%g
|
|
|
|
(numeric) real GID of dumped process
|
|
|
|
.TP
|
|
|
|
%s
|
|
|
|
number of signal causing dump
|
|
|
|
.TP
|
|
|
|
%t
|
|
|
|
time of dump, expressed as seconds since the Epoch (00:00h, 1\ Jan 1970, UTC)
|
|
|
|
.TP
|
|
|
|
%h
|
|
|
|
hostname (same as \fInodename\fP returned by \fBuname\fP(2))
|
|
|
|
.TP
|
|
|
|
%e
|
|
|
|
executable filename (without path prefix)
|
|
|
|
.TP
|
|
|
|
%c
|
|
|
|
core file size soft resource limit of crashing process (since Linux 2.6.24)
|
|
|
|
.PD
|
|
|
|
.RE
|
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
A single % at the end of the template is dropped from the
|
|
|
|
core filename, as is the combination of a % followed by any
|
2006-03-31 07:05:11 +00:00
|
|
|
character other than those listed above.
|
|
|
|
All other characters in the template become a literal
|
|
|
|
part of the core filename.
|
2008-06-09 15:49:35 +00:00
|
|
|
The template may include \(aq/\(aq characters, which are interpreted
|
2006-03-31 07:05:11 +00:00
|
|
|
as delimiters for directory names.
|
2008-06-12 04:59:28 +00:00
|
|
|
The maximum size of the resulting core filename is 128 bytes (64 bytes
|
|
|
|
in kernels before 2.6.19).
|
2006-03-31 07:05:11 +00:00
|
|
|
The default value in this file is "core".
|
|
|
|
For backward compatibility, if
|
|
|
|
.I /proc/sys/kernel/core_pattern
|
|
|
|
does not include "%p" and
|
|
|
|
.I /proc/sys/kernel/core_uses_pid
|
|
|
|
(see below)
|
2008-03-19 13:16:39 +00:00
|
|
|
is non-zero, then .PID will be appended to the core filename.
|
2006-03-31 07:05:11 +00:00
|
|
|
|
2006-11-25 01:45:17 +00:00
|
|
|
Since version 2.4, Linux has also provided
|
|
|
|
a more primitive method of controlling
|
2006-03-31 07:05:11 +00:00
|
|
|
the name of the core dump file.
|
|
|
|
If the
|
|
|
|
.I /proc/sys/kernel/core_uses_pid
|
|
|
|
file contains the value 0, then a core dump file is simply named
|
|
|
|
.IR core .
|
2008-03-19 13:16:39 +00:00
|
|
|
If this file contains a non-zero value, then the core dump file includes
|
2006-03-31 07:05:11 +00:00
|
|
|
the process ID in a name of the form
|
|
|
|
.IR core.PID .
|
2008-06-12 04:59:28 +00:00
|
|
|
.SS Piping core dumps to a program
|
|
|
|
Since kernel 2.6.19, Linux supports an alternate syntax for the
|
|
|
|
.I /proc/sys/kernel/core_pattern
|
|
|
|
file.
|
|
|
|
If the first character of this file is a pipe symbol (\fB|\fP),
|
|
|
|
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.
|
|
|
|
Note the following points:
|
|
|
|
.IP * 3
|
|
|
|
The program must be specified using an absolute pathname (or a
|
|
|
|
pathname relative to the root directory, \fI/\fP),
|
|
|
|
and must immediately follow the '|' character.
|
|
|
|
.IP *
|
|
|
|
The process created to run the program runs as user and group
|
|
|
|
.IR root .
|
|
|
|
.IP *
|
|
|
|
Command-line arguments can be supplied to the
|
|
|
|
program (since kernel 2.6.24),
|
|
|
|
delimited by white space (up to a total line length of 128 bytes).
|
|
|
|
.IP *
|
|
|
|
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
|
|
|
|
.I %p
|
|
|
|
in an argument.
|
|
|
|
.SS Controlling which mappings are written to the core dump
|
|
|
|
Since kernel 2.6.23, the Linux-specific
|
|
|
|
.IR /proc/PID/coredump_filter
|
|
|
|
file can be used to control which memory segments are written to the
|
|
|
|
core dump file in the event that a core dump is performed for the
|
|
|
|
process with the corresponding process ID.
|
|
|
|
|
|
|
|
The value in the file is a bit mask of memory mapping types (see
|
|
|
|
.BR mmap (2)).
|
|
|
|
If a bit is set in the mask, then memory mappings of the
|
|
|
|
corresponding type are dumped; otherwise they are not dumped.
|
|
|
|
The bits in this file have the following meanings:
|
|
|
|
.PP
|
|
|
|
.PD 0
|
|
|
|
.RS 4
|
|
|
|
.TP
|
|
|
|
bit 0
|
|
|
|
Dump anonymous private mappings.
|
|
|
|
.TP
|
|
|
|
bit 1
|
|
|
|
Dump anonymous shared mappings.
|
|
|
|
.TP
|
|
|
|
bit 2
|
|
|
|
Dump file-backed private mappings.
|
|
|
|
.TP
|
|
|
|
bit 3
|
|
|
|
Dump file-backed shared mappings.
|
|
|
|
.\" file-backed shared mappings of course also update the underlying
|
|
|
|
.\" mapped file.
|
|
|
|
.RE
|
|
|
|
.PD
|
|
|
|
.PP
|
|
|
|
The default value of
|
|
|
|
.I coredump_filter
|
|
|
|
is 0x3;
|
|
|
|
this reflects traditional Linux behavior and means that
|
|
|
|
only anonymous memory segments are dumped.
|
|
|
|
|
2008-06-12 11:52:08 +00:00
|
|
|
Memory-mapped I/O pages such as frame buffer are never dumped, and
|
2008-06-12 04:59:28 +00:00
|
|
|
virtual DSO pages are always dumped, regardless of the
|
|
|
|
.I coredump_filter
|
|
|
|
value.
|
|
|
|
|
|
|
|
A child process created via
|
|
|
|
.BR fork (2)
|
|
|
|
inherits its parents
|
|
|
|
.I coredump_filter
|
|
|
|
value;
|
2008-06-12 11:52:08 +00:00
|
|
|
the
|
2008-06-12 04:59:28 +00:00
|
|
|
.I coredump_filter
|
|
|
|
value is preserved across an
|
|
|
|
.BR execve (2).
|
|
|
|
|
|
|
|
It can be useful to set
|
|
|
|
.I coredump_filter
|
|
|
|
in the parent shell before running a program, for example:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " echo 0x7 > /proc/self/coredump_filter"
|
|
|
|
.RB "$" " ./some_program"
|
2008-06-12 04:59:28 +00:00
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
This file is only provided if the kernel was built with the
|
2008-07-02 13:38:55 +00:00
|
|
|
.B CONFIG_ELF_CORE
|
|
|
|
configuration option.
|
2006-03-31 07:05:11 +00:00
|
|
|
.SH NOTES
|
2007-04-12 22:42:49 +00:00
|
|
|
The
|
2006-03-31 07:05:11 +00:00
|
|
|
.BR gdb (1)
|
|
|
|
.I gcore
|
|
|
|
command can be used to obtain a core dump of a running process.
|
2006-04-15 01:11:58 +00:00
|
|
|
|
|
|
|
If a multithreaded process (or, more precisely, a process that
|
|
|
|
shares its memory with another process by being created with the
|
|
|
|
.B CLONE_VM
|
|
|
|
flag of
|
|
|
|
.BR clone (2))
|
2007-04-12 22:42:49 +00:00
|
|
|
dumps core, then the process ID is always appended to the core filename,
|
2006-04-15 20:58:17 +00:00
|
|
|
unless the process ID was already included elsewhere in the
|
|
|
|
filename via a %p specification in
|
2006-04-15 01:11:58 +00:00
|
|
|
.IR /proc/sys/kernel/core_pattern .
|
2007-06-16 11:32:28 +00:00
|
|
|
(This is primarily useful when employing the LinuxThreads implementation,
|
|
|
|
where each thread of a process has a different PID.)
|
2006-04-15 21:31:43 +00:00
|
|
|
.\" Always including the PID in the name of the core file made
|
|
|
|
.\" sense for LinuxThreads, where each thread had a unique PID,
|
2007-06-16 08:52:28 +00:00
|
|
|
.\" but doesn't seem to serve any purpose with NPTL, where all the
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" threads in a process share the same PID (as POSIX.1 requires).
|
2007-06-08 09:56:56 +00:00
|
|
|
.\" Probably the behavior is maintained so that applications using
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" LinuxThreads continue appending the PID (the kernel has no easy
|
|
|
|
.\" way of telling which threading implementation the userspace
|
2006-04-15 20:58:17 +00:00
|
|
|
.\" application is using). -- mtk, April 2006
|
2008-06-12 04:59:28 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
The program below can be used to demonstrate the use of the
|
2008-06-12 11:52:08 +00:00
|
|
|
pipe syntax in the
|
2008-06-12 04:59:28 +00:00
|
|
|
.I /proc/sys/kernel/core_pattern
|
|
|
|
file.
|
|
|
|
The following shell session demonstrates the use of this program
|
|
|
|
(compiled to create an executable named
|
|
|
|
.IR core_pattern_pipe_test ):
|
|
|
|
.PP
|
|
|
|
.in +4n
|
|
|
|
.nf
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
|
|
|
|
.RB "$" " su"
|
2008-06-12 04:59:28 +00:00
|
|
|
Password:
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "#" " echo \(aq|$PWD/core_pattern_pipe_test %p \
|
|
|
|
UID=%u GID=%g sig=%s\(aq > \e"
|
|
|
|
.B " /proc/sys/kernel/core_pattern"
|
|
|
|
.RB "#" " exit"
|
|
|
|
.RB "$" " sleep 100"
|
|
|
|
.BR "^\e" " # type control-backslash"
|
2008-06-12 04:59:28 +00:00
|
|
|
Quit (core dumped)
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " cat core.info"
|
2008-06-12 04:59:28 +00:00
|
|
|
argc=5
|
|
|
|
argc[0]=</home/mtk/core_pattern_pipe_test>
|
|
|
|
argc[1]=<20575>
|
|
|
|
argc[2]=<UID=1000>
|
|
|
|
argc[3]=<GID=100>
|
|
|
|
argc[4]=<sig=3>
|
|
|
|
Total bytes in core dump: 282624
|
|
|
|
.fi
|
|
|
|
.in
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strtol.3, core.5: global fix: Add ".SS Program source" to EXAMPLE
Add ".SS Program source" to clearly distinguish shell session and
descriptive text from actual program code.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:51:05 +00:00
|
|
|
.SS Program source
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getaddrinfo.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5: srcfix
s/\.R " "/\\\&/ as a way of getting a blank line after a .SS heading.
(Suggested by Sam Varshavchik <mrsam@courier-mta.com>)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-11-05 01:42:45 +00:00
|
|
|
\&
|
2008-06-12 04:59:28 +00:00
|
|
|
.nf
|
|
|
|
/* core_pattern_pipe_test.c */
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define BUF_SIZE 1024
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int tot, j;
|
|
|
|
ssize_t nread;
|
|
|
|
char buf[BUF_SIZE];
|
|
|
|
FILE *fp;
|
|
|
|
char cwd[PATH_MAX];
|
|
|
|
|
2008-06-12 11:52:08 +00:00
|
|
|
/* Change our current working directory to that of the
|
2008-06-12 04:59:28 +00:00
|
|
|
crashing process */
|
|
|
|
|
|
|
|
snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
|
|
|
|
chdir(cwd);
|
|
|
|
|
|
|
|
/* Write output to file "core.info" in that directory */
|
|
|
|
|
|
|
|
fp = fopen("core.info", "w+");
|
|
|
|
if (fp == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
/* Display command\-line arguments given to core_pattern
|
|
|
|
pipe program */
|
|
|
|
|
|
|
|
fprintf(fp, "argc=%d\\n", argc);
|
|
|
|
for (j = 0; j < argc; j++)
|
|
|
|
fprintf(fp, "argc[%d]=<%s>\\n", j, argv[j]);
|
|
|
|
|
|
|
|
/* Count bytes in standard input (the core dump) */
|
|
|
|
|
|
|
|
tot = 0;
|
2008-06-12 11:52:08 +00:00
|
|
|
while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
|
2008-06-12 04:59:28 +00:00
|
|
|
tot += nread;
|
|
|
|
fprintf(fp, "Total bytes in core dump: %d\\n", tot);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
.fi
|
2006-03-31 07:05:11 +00:00
|
|
|
.SH SEE ALSO
|
2008-08-26 18:16:56 +00:00
|
|
|
.BR bash (1),
|
2006-03-31 07:05:11 +00:00
|
|
|
.BR gdb (1),
|
|
|
|
.BR getrlimit (2),
|
2008-07-01 14:02:46 +00:00
|
|
|
.BR mmap (2),
|
2006-03-31 07:05:11 +00:00
|
|
|
.BR prctl (2),
|
|
|
|
.BR sigaction (2),
|
|
|
|
.BR elf (5),
|
|
|
|
.BR proc (5),
|
2007-06-16 11:32:28 +00:00
|
|
|
.BR pthreads (7),
|
2006-03-31 07:05:11 +00:00
|
|
|
.BR signal (7)
|