proc_getattr Subroutine
Purpose
Retrieves selected attributes of a process.
Library
Standard C library (libc.a)
Syntax
#include <sys/proc.h>
int proc_getattr (pid,attr,size)
pid_t pid;
procattr_t* attr;
size64_t size;
Description
The proc_getattr subroutines allows you to retrieve the current state of certain process attributes. The information is returned in the procattr_t structure defined in the <sys/proc.h> header file.
typedef struct {
uchar core_naming; /* Unique core file names */
uchar core_mmap; /* Dump nonanonymous mmap regions to core file */
uchar core_shm; /* Dump shared memory to core file */
uchar aixthread_hrt; /* High resolution timer for thread */
}procattr_t;
To retrieve information about the calling process, a -1 can be passed as the first argument, pid.
Process A can retrieve process attribute information about Process B if one or more of the following items are true:
- Process A and Process B have the same real or effective user ID.
- Process A was executed by the root user.
- Process A has the PV_DAC_R privilege.
Parameters
Item | Description |
---|---|
pid | Specified the process identifier of the process for which the information is to be retrieved. |
attr | Specifies apointer to the user structure that holds the information retrieved from the process kernel structure. |
size | The sizeof procattr_t structure is stored in the size parameter when calling the API. |
Return Values
Item | Description |
---|---|
0 | proc_getattr was successful. |
-1 | proc_getattr was unsuccessful. Global variable errno is set to indicate the error. |
Error Codes
Item | Description |
---|---|
EINVAL | The size argument does not match the size of the procattr_t in the kernel. |
EFAULT | The attr value that was passed to the buffer is invalid. |
ESRCH | The process identifier could not be located. |
EPERM | The privileges are insufficient to read attributes from the target proc structure. |
Example
#include <stdio.h>
#include <sys/proc.h>
dispprocflags.c:
#define P(_x_) (((_x_) == PA_ENABLE) ? "ENABLE" : \
((_x_) == PA_DISABLE ? "DISABLE" : \
(((_x_) == PA_IGNORE) ? "IGNORE" : "JUNK")))
int main(int argc, char *argv[])
{
int rc;
procattr_t attr;
pid_t pid;
if (argc < ) {
printf("Syntax: %s <pid>\n", argv[0]);
exit(-1);
}
pid = atoi(argv[1]);
bzero(&attr, sizeof(procattr_t));
rc = proc_getattr(pid, &attr, sizeof(procattr_t));
if (rc) {
printf("proc_getattr failed, errno %d\n", errno);
exit(-1);
}
printf("core_naming %s\n", P(attr.core_naming));
printf("core_mmap %s\n", P(attr.core_mmap));
printf("core_shm %s\n", P(attr.core_shm));
printf("aixthread_hrt %s\n", P(attr.aixthread_hrt));
}
crash64.c:
#include <stdio.h>
int main()
{
int *p = (int *)0x100;
pid_t pid = getpid();
printf("My pid is %d\n", getpid());
getchar();
*p = 0x10;
printf("Done\n");
}
# ./crash64 & [2]
5570812
# My pid is 5570812
# ./dispcoreflags 5570812
PID 5500FC
core_naming ENABLE
core_mmap ENABLE
core_shm ENABLE
aixthread_hrt DISABLE
# fg ./crash64
Memory fault(coredump)
# ls core*
core.5570812.11054349