MCPcopy Create free account
hub / github.com/F-Stack/f-stack / racct_proc_fork

Function racct_proc_fork

freebsd/kern/kern_racct.c:916–969  ·  view source on GitHub ↗

* Inherit resource usage information from the parent process. */

Source from the content-addressed store, hash-verified

914 * Inherit resource usage information from the parent process.
915 */
916int
917racct_proc_fork(struct proc *parent, struct proc *child)
918{
919 int i, error = 0;
920
921 if (!racct_enable)
922 return (0);
923
924 /*
925 * Create racct for the child process.
926 */
927 racct_create(&child->p_racct);
928
929 PROC_LOCK(parent);
930 PROC_LOCK(child);
931 RACCT_LOCK();
932
933#ifdef RCTL
934 error = rctl_proc_fork(parent, child);
935 if (error != 0)
936 goto out;
937#endif
938
939 /* Init process cpu time. */
940 child->p_prev_runtime = 0;
941 child->p_throttled = 0;
942
943 /*
944 * Inherit resource usage.
945 */
946 for (i = 0; i <= RACCT_MAX; i++) {
947 if (parent->p_racct->r_resources[i] == 0 ||
948 !RACCT_IS_INHERITABLE(i))
949 continue;
950
951 error = racct_set_locked(child, i,
952 parent->p_racct->r_resources[i], 0);
953 if (error != 0)
954 goto out;
955 }
956
957 error = racct_add_locked(child, RACCT_NPROC, 1, 0);
958 error += racct_add_locked(child, RACCT_NTHR, 1, 0);
959
960out:
961 RACCT_UNLOCK();
962 PROC_UNLOCK(child);
963 PROC_UNLOCK(parent);
964
965 if (error != 0)
966 racct_proc_exit(child);
967
968 return (error);
969}
970
971/*
972 * Called at the end of fork1(), to handle rules that require the process

Callers 1

fork1Function · 0.70

Calls 5

racct_createFunction · 0.85
rctl_proc_forkFunction · 0.85
racct_set_lockedFunction · 0.85
racct_add_lockedFunction · 0.85
racct_proc_exitFunction · 0.70

Tested by

no test coverage detected