kernel/exit.c
Source file repositories/reference/linux-study-clean/kernel/exit.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/exit.c- Extension
.c- Size
- 51651 bytes
- Lines
- 2034
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/slab.hlinux/sched/autogroup.hlinux/sched/mm.hlinux/sched/stat.hlinux/sched/task.hlinux/sched/task_stack.hlinux/sched/cputime.hlinux/interrupt.hlinux/module.hlinux/capability.hlinux/completion.hlinux/personality.hlinux/tty.hlinux/iocontext.hlinux/key.hlinux/cpu.hlinux/acct.hlinux/tsacct_kern.hlinux/file.hlinux/freezer.hlinux/binfmts.hlinux/nsproxy.hlinux/pid_namespace.hlinux/ptrace.hlinux/profile.hlinux/mount.hlinux/proc_fs.hlinux/kthread.hlinux/mempolicy.hlinux/taskstats_kern.hlinux/delayacct.h
Detected Declarations
syscall exitsyscall exit_groupsyscall waitidsyscall wait4syscall waitpidstruct release_task_postfunction kernel_exit_sysctls_initfunction oops_count_showfunction kernel_exit_sysfs_initfunction __unhash_processfunction __exit_signalfunction delayed_put_task_structfunction put_task_struct_rcu_userfunction release_threadfunction rcuwait_wake_upfunction will_become_orphaned_pgrpfunction do_each_pid_taskfunction is_current_pgrp_orphanedfunction has_stopped_jobsfunction do_each_pid_taskfunction kill_orphaned_pgrpfunction coredump_task_exitfunction __try_to_set_ownerfunction try_to_set_ownerfunction for_each_threadfunction mm_update_next_ownerfunction exit_mm_sched_cachefunction exit_mm_sched_cachefunction for_each_threadfunction list_for_each_entry_safefunction childrenfunction reparent_leaderfunction forget_original_parentfunction for_each_threadfunction exit_notifyfunction list_for_each_entry_safefunction stack_not_usedfunction stack_not_usedfunction kstack_histogramfunction check_stack_usagefunction check_stack_usagefunction do_exitfunction make_task_deadfunction sys_exit_groupfunction wait4function eligible_pidfunction eligible_childfunction read_lock
Annotated Snippet
SYSCALL_DEFINE1(exit, int, error_code)
{
do_exit((error_code&0xff)<<8);
}
/*
* Take down every thread in the group. This is called by fatal signals
* as well as by sys_exit_group (below).
*/
void __noreturn
do_group_exit(int exit_code)
{
struct signal_struct *sig = current->signal;
if (sig->flags & SIGNAL_GROUP_EXIT)
exit_code = sig->group_exit_code;
else if (sig->group_exec_task)
exit_code = 0;
else {
struct sighand_struct *const sighand = current->sighand;
spin_lock_irq(&sighand->siglock);
if (sig->flags & SIGNAL_GROUP_EXIT)
/* Another thread got here before we took the lock. */
exit_code = sig->group_exit_code;
else if (sig->group_exec_task)
exit_code = 0;
else {
sig->group_exit_code = exit_code;
sig->flags = SIGNAL_GROUP_EXIT;
zap_other_threads(current);
}
spin_unlock_irq(&sighand->siglock);
}
do_exit(exit_code);
/* NOTREACHED */
}
/*
* this kills every thread in the thread group. Note that any externally
* wait4()-ing process will get the correct exit code - even if this
* thread is not the thread group leader.
*/
SYSCALL_DEFINE1(exit_group, int, error_code)
{
do_group_exit((error_code & 0xff) << 8);
/* NOTREACHED */
return 0;
}
static int eligible_pid(struct wait_opts *wo, struct task_struct *p)
{
return wo->wo_type == PIDTYPE_MAX ||
task_pid_type(p, wo->wo_type) == wo->wo_pid;
}
static int
eligible_child(struct wait_opts *wo, bool ptrace, struct task_struct *p)
{
if (!eligible_pid(wo, p))
return 0;
/*
* Wait for all children (clone and not) if __WALL is set or
* if it is traced by us.
*/
if (ptrace || (wo->wo_flags & __WALL))
return 1;
/*
* Otherwise, wait for clone children *only* if __WCLONE is set;
* otherwise, wait for non-clone children *only*.
*
* Note: a "clone" child here is one that reports to its parent
* using a signal other than SIGCHLD, or a non-leader thread which
* we can only see if it is traced by us.
*/
if ((p->exit_signal != SIGCHLD) ^ !!(wo->wo_flags & __WCLONE))
return 0;
return 1;
}
/*
* Handle sys_wait4 work for one task in state EXIT_ZOMBIE. We hold
* read_lock(&tasklist_lock) on entry. If we return zero, we still hold
* the lock and this task is uninteresting. If we return nonzero, we have
* released the lock and the system call should return.
*/
Annotation
- Immediate include surface: `linux/mm.h`, `linux/slab.h`, `linux/sched/autogroup.h`, `linux/sched/mm.h`, `linux/sched/stat.h`, `linux/sched/task.h`, `linux/sched/task_stack.h`, `linux/sched/cputime.h`.
- Detected declarations: `syscall exit`, `syscall exit_group`, `syscall waitid`, `syscall wait4`, `syscall waitpid`, `struct release_task_post`, `function kernel_exit_sysctls_init`, `function oops_count_show`, `function kernel_exit_sysfs_init`, `function __unhash_process`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.