0

在 C 中,是否可以将一个结构嵌套在另一个结构中?我将如何访问内部结构的字段?以结构体kinfo_proc为例:

struct kinfo_proc {
  struct  extern_proc kp_proc;      /* proc structure */
  struct  eproc {
    struct  proc *e_paddr;    /* address of proc */
    struct  session *e_sess;  /* session pointer */
    struct  _pcred e_pcred;   /* process credentials */
    struct  _ucred e_ucred;   /* current credentials */
    struct   vmspace e_vm;    /* address space */
    pid_t e_ppid;     /* parent process id */
    pid_t e_pgid;     /* process group id */
    short e_jobc;     /* job control counter */
    dev_t e_tdev;     /* controlling tty dev */
    pid_t e_tpgid;    /* tty process group id */
    struct  session *e_tsess; /* tty session pointer */
#define WMESGLEN  7
    char  e_wmesg[WMESGLEN+1];  /* wchan message */
    segsz_t e_xsize;    /* text size */
    short e_xrssize;    /* text rss */
    short e_xccount;    /* text references */
    short e_xswrss;
    int32_t e_flag;
#define EPROC_CTTY  0x01  /* controlling tty vnode active */
#define EPROC_SLEADER 0x02  /* session leader */
#define COMAPT_MAXLOGNAME 12
    char  e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */
#if CONFIG_LCTX
    pid_t e_lcid;
    int32_t e_spare[3];
#else
    int32_t e_spare[4];
#endif
  } kp_eproc;
};

我将如何尝试获取新创建的 kinfo_proc 实例的 e_ppid?

4

1 回答 1

4

您将创建类似:

struct kinfo_proc test1;
test1.kp_eproc.e_ppid /// Access it like this.
于 2012-08-09T19:59:53.897 回答