、Linuxカーネルは(例えばfork()
に)copy_process
機能 http://lxr.free-electrons.com/source/kernel/fork.c?v=4.8#L1371
1371 if (atomic_read(&p->real_cred->user->processes) >=
1372 task_rlimit(p, RLIMIT_NPROC)) {
又はsys_execve
(FS/exec.cでdo_execveat_common
)中で&p->real_cred->user->processes
フィールドを読み取り:
1504 if ((current->flags & PF_NPROC_EXCEEDED) &&
1505 atomic_read(¤t_user()->processes) > rlimit(RLIMIT_NPROC)) {
1506 retval = -EAGAIN;
1507 goto out_ret;
したがって、processes
がRLIMIT_NPROCより大きい場合、関数は失敗します。このフィールドは、だから、プロセス数の会計はユーザーごとです
atomic_t processes; /* How many processes does this user have? */
としてsched.hにstruct cred
real_credでアクセス(struct user_struct
の一部として定義されて
フィールドの減少が失敗した場合にcopy_processである:。
1655 bad_fork_cleanup_count:
1656 atomic_dec(&p->cred->user->processes);
とフィールドの増分はcopy_cred
である:http://code.metager.de/source/xref/linux/stable/kernel/cred.c#313
313 /*
314 * Copy credentials for the new process created by fork()
315 *
316 * We share if we can, but under some circumstances we have to generate a new
317 * set.
318 *
319 * The new process gets the current process's subjective credentials as its
320 * objective and subjective credentials
321 */
322 int copy_creds(struct task_struct *p, unsigned long clone_flags)
339 atomic_inc(&p->cred->user->processes);
372 atomic_inc(&new->user->processes);
manページは、ユーザごとの上限であることを言う:http://man7.org/linux/man-pages/man2/setrlimit.2.html
RLIMIT_NPROC
The maximum number of processes (or, more precisely on Linux,
threads) that can be created for the real user ID of the
calling process. Upon encountering this limit, fork(2) fails
with the error EAGAIN.
さてあなたは、あなたが実際にあなたが持っている成功し 'フォーク()'システムコールの数によって生成されたプロセスの数を知ることができますあなたはフォークが '0'を返すたびにそれらを数えなければなりません。あなたが成功した 'wait(2)'呼び出しの回数も考慮する場合は、作成したプロセスの総数、アクティブな数(それらを差し引いたもの)、完了したプロセスの数が得られます。 –
ところで、実際にフォークしていないプロセスの数を知っていると、システムにセキュリティの問題があります。 –