proc_setattr 子例程

用途

设置流程的所选属性。

标准 C 库 (libc.a)

语法

#include <sys/proc.h>
int proc_setattr (pid,attr,size)
pid_t pid;
procattr_t* attr;
size64_t size;

描述

proc_setattr 子例程允许您设置进程的所选属性。 所选属性的列表在 <sys/proc.h> 头文件中定义的procattr_t 结构中定义。

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;

要为调用进程设置属性,第一个参数pid 可以为-1。

如果以下一个或多个项为 true ,那么流程 A 可以为流程 B 设置流程属性:

  • 流程 A 和流程 B 具有相同的实际或有效用户标识。
  • 进程 A 已由 root 用户执行。
  • 进程 A 具有 PV_DAC_W 特权。

参数

描述
pid 要检索其信息的进程的标识。
attr 一个指向用户结构的指针,该用户结构将保存从进程内核结构中检索的信息。
大小 调用 API 时, sizeof procattr_t 结构存储在 size 参数中。

返回值

描述
重大安全事件数量 proc_setattr 成功。
-1 proc_setattr 失败。 全局变量 errno 设置为指示错误。

错误代码

描述
EINVAL size 自变量与内核中 procattr_t 的大小不匹配。
Efault 传递到缓冲区的 attr 值无效。
ESRCH 找不到进程标识。
EPERM 特权不足,无法从 proc 结构的目标读取属性。

示例

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 &lt; ) { 
                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