gencore or coredump Subroutine

Purpose

Creates a core file without terminating the process.

Library

Standard C Library (libc.a)

Syntax

#include <core.h>

int gencore (coredumpinfop)
struct coredumpinfo *coredumpinfop;

int coredump (coredumpinfop)
struct coredumpinfo *coredumpinfop;

Description

The gencore and coredump subroutines create a core file of a process without terminating it. The core file contains the snapshot of the process at the time the call is made and can be used with the dbx command for debugging purposes.

If any thread of the process is in a system call when its snapshot core file is generated, the register information returned may not be reliable (except for the stack pointer). To save all user register contents when a system call is made so that they are available to the gencore and coredump subroutines, the application should be built using the "-bM:UR" flags.

If any thread of the process is sleeping inside the kernel or stopped (possibly for job control), the caller of the gencore and coredump subroutines will also be blocked until the thread becomes runnable again. Thus, these subroutines may take a long time to complete depending upon the target process state.

The coredump subroutine always generates a core file for the process from which it is called. This subroutine has been replaced by the gencore subroutine and is being provided for compatibility reasons only.

The gencore subroutine creates a core file for the process whose process ID is specified in the pid field of the coredumpinfo structure. For security measures, the user ID (uid) and group ID (gid) of the core file are set to the uid and gid of the process.

Both these subroutines return success even if the core file cannot be created completely because of filesystem space constraints. When using the dbx command with an incomplete core file, dbx may warn that the core file is truncated.

In the "Change / Show Characteristics of Operating System" smitty screen, there are two options regarding the creation of the core file. The core file will always be created in the default core format and will ignore the value specified in the "Use pre-430 style CORE dump" option. However, the value specified for the "Enable full CORE dump" option will be considered when creating the core file. Resource limits of the target process for file and coredump will be enforced.

The coredumpinfo structure contains the following fields:
Member Type Member Name Description
unsigned int length Length of the core file name.
char * name Name of the core file.
pid_t pid ID of the process to be coredumped.
int flags Flags-version flag. Set this to GENCORE_VERSION_1.
Note: The pid and flags fields are required for the gencore subroutine, but are ignored for the coredump subroutine

Parameters

Item Description
coredumpinfop Specifies the address of the coredumpinfo structure that provides the file name to save the core snapshot and its length. For the gencore subroutine, it also provides the process id of the process whose core is to be dumped and a flag which includes version flag bits. The version flag value must be set to GENCORE_VERSION_1.

Return Values

Upon successful completion, the gencore and coredump subroutines return a 0. If unsuccessful, a -1 is returned, and the errno global variable is set to indicate the error

Error Codes

Item Description
EACCES Search permission is denied on a component of the path prefix, the file exists and permissions specified by the mode are denied, or the file does not exist and write permission is denied for the parent directory of the file to be created.
ENOENT The name field in the coredumpinfo parameter points to an empty string.
EINTR The subroutine was interrupted by a signal before it could complete.
ENAMETOOLONG The value of the length field in the coredumpinfop structure or the length of the absolute path of the specified core file name is greater than MAXPATHLEN (as defined in the sys/param.h file).
EINVAL The value of the length field in the coredumpinfop structure is 0.
EAGAIN The target process is already in the middle of another gencore or coredump subroutine.
ENOMEM Unable to allocate memory resources to complete the subroutine.
In addition to the above, the following errno values can be set when the gencore subroutine is unsuccessful:
Item Description
EPERM The real or effective user ID of the calling process does not match the real or effective user ID of target process or the calling process does not have root user authority.
ESRCH There is no process whose ID matches the value specified in the pid field of the coredumpinfop parameter or the process is exiting.
EINVAL The flags field in the coredumpinfop parameter is not set to a valid version value.