<chapter id="tscore-7"><title>Managing Core Files (Tasks)</title><highlights><para>This chapter describes how to manage core files with the <command>coreadm</command> command.</para><para>For information on the procedures associated with managing core files,
see <olink targetptr="tscore-4" remap="internal">Managing Core Files (Task Map)</olink>.</para>
</highlights><sect1 id="tscore-4"><title>Managing Core Files (Task Map)</title><informaltable frame="all"><tgroup cols="3" colsep="1" rowsep="1"><colspec colname="colspec0" colwidth="110*"/><colspec colname="col2" colwidth="167*"/><colspec colname="colspec1" colwidth="119*"/><thead><row><entry><para>Task</para>
</entry><entry><para>Description</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>1. Display the current core dump configuration</para>
</entry><entry><para>Display the current core dump configuration by using the <command>coreadm</command> command.</para>
</entry><entry><para><olink targetptr="tscore-5" remap="internal">How to Display the Current Core Dump Configuration</olink></para>
</entry>
</row><row><entry><para>2. Modify the core dump configuration</para>
</entry><entry><para>Modify the core dump configuration to do one of the following:</para><para>Set a core file name pattern.</para><para></para><para></para><para>Enable a per-process core file path.</para><para></para><para></para><para>Enable a global core file path.</para>
</entry><entry><para></para><para><olink targetptr="tscore-6" remap="internal">How to Set a Core File Name Pattern</olink></para><para><olink targetptr="tscore-12" remap="internal">How to Enable a Per-Process Core File Path</olink></para><para><olink targetptr="tscore-14" remap="internal">How to Enable a Global Core File Path</olink></para>
</entry>
</row><row><entry><para>3. Examine a Core Dump File</para>
</entry><entry><para> Use the <command>proc</command> tools to view a core dump file. </para>
</entry><entry><para><olink targetptr="tscore-11" remap="internal">Examining Core Files</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect1><sect1 id="tscore-8"><title>Managing Core Files Overview</title><para>Core files are generated when a process or application terminates
abnormally. Core files are managed with the <command>coreadm</command> command.</para><para>For example, you can use the <command>coreadm</command> command to configure
a system so that all process core files are placed in a single system directory.
This means it is easier to track problems by examining the core files in a
specific directory whenever a Solaris process or daemon terminates abnormally.</para><sect2 id="tscore-9"><title>Configurable Core File Paths</title><itemizedlist><para>Two new configurable <filename>core</filename> file paths that can be
enabled or disabled independently of each other are:</para><listitem><para>A
per-process core file path, which defaults to <filename>core</filename> and
is enabled by default. If enabled, the per-process core file path causes a <filename>core</filename> file to be produced when the process terminates abnormally.
The per-process path is inherited by a new process from its parent process. </para><para>When generated, a per-process core file is owned by the owner of the
process with read/write permissions for the owner. Only the owning user can
view this file.</para>
</listitem><listitem><para>A global core file
path, which defaults to <filename>core</filename> and is disabled by default.
If enabled, an <emphasis>additional</emphasis> core file with the same content
as the per-process core file is produced by using the global core file path.</para><para>When generated, a global core file is owned by superuser with read/write
permissions for superuser only. Non-privileged users cannot view this file.</para>
</listitem>
</itemizedlist><para>When a process terminates abnormally, it produces a core file in the
current directory by default. If the global core file path is enabled, each
abnormally terminating process might produce two files, one in the current
working directory, and one in the global core file location.</para><para>By default, a <literal>setuid</literal> process does not produce core
files using either the global or per-process path.</para>
</sect2><sect2 id="tscore-1"><title>Expanded Core File Names</title><para>If a global core file directory is enabled, <filename>core</filename> files
can be distinguished from one another by using the variables described in
the following table.</para><informaltable frame="all"><tgroup cols="2" colsep="1" rowsep="1"><colspec colname="colspec0" colwidth="143.19*"/><colspec colname="colspec1" colwidth="252.81*"/><thead><row><entry><para>Variable Name</para>
</entry><entry><para>Variable Definition</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>%d</literal></para>
</entry><entry><para>Executable file directory name, up to a maximum of <literal>MAXPATHLEN</literal> characters</para>
</entry>
</row><row><entry><para><literal>%f</literal></para>
</entry><entry><para>Executable file name, up to a maximum of <literal>MAXCOMLEN</literal> characters</para>
</entry>
</row><row><entry><para><literal>%g</literal></para>
</entry><entry><para>Effective group ID</para>
</entry>
</row><row><entry><para><literal>%m</literal></para>
</entry><entry><para>Machine name (<command>uname -m</command>)</para>
</entry>
</row><row><entry><para><literal>%n</literal></para>
</entry><entry><para>System node name )<command>uname -n</command>)</para>
</entry>
</row><row><entry><para><literal>%p</literal></para>
</entry><entry><para>Process ID</para>
</entry>
</row><row><entry><para><literal>%t</literal></para>
</entry><entry><para>Decimal value of time(2)</para>
</entry>
</row><row><entry><para><literal>%u</literal></para>
</entry><entry><para>Effective user ID</para>
</entry>
</row><row><entry><para><literal>%z</literal></para>
</entry><entry><para>Name of the zone in which process is executed (<literal>zonename</literal>)</para>
</entry>
</row><row><entry><para><literal>%%</literal></para>
</entry><entry><para>Literal %</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><para>For example, if the global core file path is set to: </para><para><literal>/var/core/core.%f.%p</literal></para><para>and a <literal>sendmail</literal> process with PID <literal>12345</literal> terminates
abnormally, it produces the following <literal>core</literal> file:</para><para><literal>/var/core/core.sendmail.12345</literal></para>
</sect2><sect2 id="tscore-2"><title>Setting the Core File Name Pattern</title><para>You can set a core file name pattern on a global, zone, or per-process
basis. In addition, you can set the per-process defaults that persist across
a system reboot.</para><para>For example, the following <command>coreadm</command> command sets the
default per-process core file pattern. This setting applies to all processes
that have not explicitly overridden the default core file pattern. This setting
persists across system reboots.</para><screen># <userinput>coreadm -i /var/core/core.%f.%p</userinput></screen><para>This <command>coreadm</command> command sets the per-process core file
name pattern for any processes:</para><screen>$ <userinput>coreadm -p /var/core/core.%f.%p $$</userinput></screen><para>The <literal>$$</literal> symbols represent a placeholder for the process
ID of the currently running shell. The per-process core file name pattern
is inherited by all child processes.</para><para>Once a global or per-process core file name pattern is set, it must
be enabled with the <command>coreadm -e</command> command. See the following
procedures for more information.</para><para>You can set the core file name pattern for all processes run during
a user's login session by putting the command in a user's <filename>$HOME/.profile</filename> or <filename>.login</filename> file.</para>
</sect2><sect2 id="tscore-3"><title>Enabling <literal>setuid</literal> Programs to
Produce Core Files</title><itemizedlist><para>You can use the <command>coreadm</command> command to enable or disable <literal>setuid</literal> programs to produce core files for all system processes or
on a per-process basis by setting the following paths:</para><listitem><para>If the global <literal>setuid</literal> option
is enabled, a global core file path allows all <literal>setuid</literal> programs
on a system to produce <literal>core</literal> files.</para>
</listitem><listitem><para>If the per-process <literal>setuid</literal> option is enable,
a per-process core file path allows specific <literal>setuid</literal> processes
to produce <literal>core</literal> files. </para>
</listitem>
</itemizedlist><para>By default, both flags are disabled. For security reasons, the global
core file path must be a full pathname, starting with a leading <literal>/</literal>.
If superuser disables per-process core files, individual users cannot obtain
core files. </para><para>The <literal>setuid</literal> core files are owned by superuser with
read/write permissions for superuser only. Regular users cannot access them
even if the process that produced the <literal>setuid</literal> core file
was owned by an ordinary user. </para><para>For more information, see <olink targetdoc="refman" targetptr="coreadm-1m" remap="external"><citerefentry><refentrytitle>coreadm</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink>.</para>
</sect2><sect2 id="tscore-5"><title>How to Display the Current Core Dump Configuration</title><para>Use
the <command>coreadm</command> command without any options to display the
current core dump configuration.</para><screen>$ <userinput>coreadm</userinput>
               global core file pattern: 
     global core file content: default
       init core file pattern: core
       init core file content: default
            global core dumps: disabled
       per-process core dumps: enabled
      global setid core dumps: disabled
 per-process setid core dumps: disabled
     global core dump logging: disabled</screen>
</sect2><task id="tscore-6"><title>How to Set a Core File Name Pattern</title><procedure remap="single-step"><step id="tscore-step-2"><para>Determine whether you want to set a per-process
or global core file and select one of the following:</para><substeps><step id="tscore-step-3"><para>Set a per-process file name pattern.</para><screen>$ <userinput>coreadm -p $HOME/corefiles/%f.%p $$</userinput></screen>
</step>&rolestep.sgm;<step id="tscore-step-4"><para>Set a global file name pattern.</para><screen># <userinput>coreadm -g /var/corefiles/%f.%p</userinput></screen>
</step>
</substeps>
</step>
</procedure>
</task><task id="tscore-12"><title>How to Enable a Per-Process Core File Path</title><procedure>&rolestep.sgm;<step id="tscore-step-6"><para>Enable a per-process core file path.</para><screen># <userinput>coreadm -e process</userinput></screen>
</step><step id="tscore-step-9"><para>Display the current process core file path
to verify the configuration.</para><screen>$ <userinput>coreadm $$</userinput>
1180:   /home/kryten/corefiles/%f.%p</screen>
</step>
</procedure>
</task><task id="tscore-14"><title>How to Enable a Global Core File Path</title><procedure>&rolestep.sgm;<step id="tscore-step-11"><para>Enable a global core file path.</para><screen># <userinput>coreadm -e global -g /var/core/core.%f.%p</userinput></screen>
</step><step id="tscore-step-14"><para>Display the current process core file path
to verify the configuration.</para><screen># <userinput>coreadm</userinput>
       global core file pattern: /var/core/core.%f.%p
     global core file content: default
       init core file pattern: core
       init core file content: default
            global core dumps: enabled
       per-process core dumps: enabled
      global setid core dumps: disabled
 per-process setid core dumps: disabled
     global core dump logging: disabled</screen>
</step>
</procedure>
</task>
</sect1><sect1 id="tscore-18"><title>Troubleshooting Core File Problems</title><variablelist termlength="wholeline"><varlistentry><term>Error Message</term><listitem><screen> 
NOTICE: 'set allow_setid_core = 1' in /etc/system is obsolete
NOTICE: Use the coreadm command instead of 'allow_setid_core'</screen>
</listitem>
</varlistentry><varlistentry><term>Cause</term><listitem><para>You have an obsolete parameter that allows <literal>setuid</literal> core
files in your <filename>/etc/system</filename> file.</para>
</listitem>
</varlistentry><varlistentry><term>Solution</term><listitem><para>Remove <literal>allow_setid_core=1</literal> from the <filename>/etc/system</filename> file. Then use the <command>coreadm</command> command to enable
global <literal>setuid</literal> core file paths.</para>
</listitem>
</varlistentry>
</variablelist>
</sect1><sect1 id="tscore-11"><title>Examining Core Files</title><para>Some of the proc tools have been enhanced to examine process core
files as well as live processes. The proc tools are utilities that can manipulate
features of the <filename>/proc</filename> file system.</para><para>The <command>/usr/proc/bin/pstack</command>, <command>pmap</command>, <command>pldd</command>, <command>pflags</command>, and <command>pcred</command> tools
can now be applied to core files by specifying the name of the core file on
the command line, similar to the way you specify a process ID to these commands.</para><para>For more information on using proc tools to examine core files, see <olink targetdoc="refman" targetptr="proc-1" remap="external"><citerefentry><refentrytitle>proc</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink>.</para><example id="tscore-10"><title>Examining Core Files With proc Tools</title><screen>$ <userinput>./a.out</userinput>
Segmentation Fault(coredump)
$ <userinput>/usr/proc/bin/pstack ./core</userinput>
core './core' of 19305: ./a.out
 000108c4 main     (1, ffbef5cc, ffbef5d4, 20800, 0, 0) + 1c
 00010880 _start   (0, 0, 0, 0, 0, 0) + b8</screen>
</example>
</sect1>
</chapter>