0

In C, is it possible to have a struct nested within another struct? How would I access the fields of the inner struct? Take the struct for kinfo_proc for example:

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;
};

How would I go about trying to get the e_ppid of a newly made kinfo_proc instance?

1 Answer 1

4

You would be creating something like :

struct kinfo_proc test1;
test1.kp_eproc.e_ppid /// Access it like this.
Sign up to request clarification or add additional context in comments.

2 Comments

i see your logic! i was missing the struct keyword. silly me. but i think "eproc" should actually be kp_eproc. when i did that it worked like a charm. thanks!
Thanks Rob. He has changed it accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.