proc_setattr Subroutine
Purpose
Sets selected attributes of a process.
Library
Standard C library (libc.a)
Syntax
#include <sys/proc.h>
int proc_setattr (pid,attr,size)
pid_t pid;
procattr_t* attr;
size64_t size;
Description
The proc_setattr subroutines allows you to set selected attributes of a process. The list of selected attributes is defined in theprocattr_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 set attributes for the calling process, a -1 can be passed as the first argument, pid.
Process A can set process attributes for 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 PV_DAC_W privilege.
Parameters
Item | Description |
---|---|
pid | The identifier of the process whose information is to be retrieved. |
attr | A pointer to the user structure that will hold the information retrieved from the process kernel structure. |
size | The sizeof procattr_t structure is stored in the size parameter when calling API. |
Return Values
Item | Description |
---|---|
0 | proc_setattr was successful. |
-1 | proc_setattr 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 passed to the buffer is invalid. |
ESRCH | Could not locate the process identifier. |
EPERM | Insufficient privileges to read attributes from target the proc structure. |
Example
setprocflags.c
#include <stdio.h>
#include <sys/proc.h>
#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;
int naming,mmap,shm = 0;
if (argc < ) {
printf("Syntax: %s <pid> <corenaming> <coremmap> <coreshm>\n", argv[0]);
exit(-1);
}
pid = atoi(argv[1]);
bzero(&attr, sizeof(procattr_t));
attr.core_naming = atoi(argv[2]);
attr.core_mmap = atoi(argv[3]);
attr.core_shm = atoi(argv[4]);
rc = proc_setattr(pid, &attr, sizeof(procattr_t));
if (rc)
{
printf("proc_getattr failed, errno %d\n", errno);
exit(-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 &
[1] 5570566
# My pid is 5570566
PID 5500FC
# ./setcoreflags 5570566 1 1 1
core_naming ENABLE
core_mmap ENABLE
core_shm ENABLE
aixthread_hrt DISABLE
# fg ./crash64
Memory fault(coredump)
# ls core*
core.5570566.11054349