+ * The p_stats and p_sigacts substructs are set in vm_fork.
+ */
+ p2->p_flag = P_INMEM;
+ if (p1->p_flag & P_PROFIL)
+ startprofclock(p2);
+ MALLOC(p2->p_cred, struct pcred *, sizeof(struct pcred),
+ M_SUBPROC, M_WAITOK);
+ bcopy(p1->p_cred, p2->p_cred, sizeof(*p2->p_cred));
+ p2->p_cred->p_refcnt = 1;
+ crhold(p1->p_ucred);
+
+ /* bump references to the text vnode (for procfs) */
+ p2->p_textvp = p1->p_textvp;
+ if (p2->p_textvp)
+ VREF(p2->p_textvp);
+
+ p2->p_fd = fdcopy(p1);
+ /*
+ * If p_limit is still copy-on-write, bump refcnt,
+ * otherwise get a copy that won't be modified.
+ * (If PL_SHAREMOD is clear, the structure is shared
+ * copy-on-write.)
+ */
+ if (p1->p_limit->p_lflags & PL_SHAREMOD)
+ p2->p_limit = limcopy(p1->p_limit);
+ else {
+ p2->p_limit = p1->p_limit;
+ p2->p_limit->p_refcnt++;
+ }
+
+ if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
+ p2->p_flag |= P_CONTROLT;
+ if (isvfork)
+ p2->p_flag |= P_PPWAIT;
+ LIST_INSERT_AFTER(p1, p2, p_pglist);
+ p2->p_pptr = p1;
+ LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling);
+ LIST_INIT(&p2->p_children);
+
+#ifdef KTRACE
+ /*
+ * Copy traceflag and tracefile if enabled.
+ * If not inherited, these were zeroed above.