ArticleslgStudy

computer science

Exit (system call)

Exit (system call) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Exit (system call) rather than just read about it. In short: On many computer operating systems, a computer process terminates its execution by making an exit system call. More generally, an exit in a multithreading environment means that a thread of execution has stopped running.

Key takeaways

  • Exit (system call) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Exit (system call) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Exit (system call) from memory before moving on to harder problems.

Reference excerpt

On many computer operating systems, a computer process terminates its execution by making an exit system call. More generally, an exit in a multithreading environment means that a thread of execution has stopped running. For resource management, the operating system reclaims resources (memory, files, etc.) that were used by the process. The process is said to be a dead process after it terminates.

How it works Under Unix and Unix-like operating systems, a process is started when its parent process executes a fork system call. The parent process may then wait for the child process to terminate, or may continue execution (possibly forking off other child processes). When the child process terminates ("dies"), either normally by calling exit, or abnormally due to a fatal exception or signal (e.g., SIGTERM, SIGINT, SIGKILL), an exit status is returned to the operating system and a SIGCHLD signal is sent to the parent process. The exit status can then be retrieved by the parent process via the wait system call. Most operating systems allow the terminating process to provide a specific exit status to the system, which is made available to the parent process. Typically this is an integer value, although some operating systems (e.g., Plan 9 from Bell Labs) allow a character string to be returned. Systems returning an integer value commonly use a zero value to indicate successful execution and non-zero values to indicate error conditions. Other systems (e.g., OpenVMS) use even-numbered values for success and odd values for errors. Still other systems (e.g., IBM z/OS and its predecessors) use ranges of integer values to indicate success, warning, and error completion results.

Cleanup The exit operation typically performs cleanup operations within the process space before returning control back to the operating system. Some systems and programming languages allow user subroutines to be registered so that they are invoked at program termination before the process actually terminates for good. As the final step of termination, a primitive system exit call is invoked, informing the operating system that the process has terminated and allows it to reclaim the resources used by the process. It is sometimes possible to bypass the usual cleanup; C99 offers the _exit() function which terminates the current process without any extra program cleanup. This may be used, for example, in a fork-exec routine when the exec call fails to replace the child process; calling atexit routines would erroneously release resources belonging to the parent.

Orphans and zombies Some operating systems handle a child process whose parent process has terminated in a special manner. Such an orphan process becomes a child of a special root process, which then waits for the child process to terminate. Likewise, a similar strategy is used to deal with a zombie process, which is a child process that has terminated but whose exit status is ignored by its parent process. Such a process becomes the child of a special parent process, which retrieves the child's exit status and allows the operating system to complete the termination of the dead process. Dealing with these special cases keeps the system's process table in a consistent state.

Examples The following programs terminate and return a success exit status to the system.

COBOL:

Fortran:

Java:

JavaScript (Node.js):Pascal:

DR-DOS batch file:

Perl:

PHP:

Python:

Rust:Unix shell:

16-bit assembly language for IBM PC compatibles:

; For MASM/TASM .MODEL SMALL .STACK .CODE main PROC NEAR MOV AH, 4Ch ; Service 4Ch - Terminate with Error Code MOV AL, 0 ; Error code INT 21h ; Interrupt 21h - DOS General Interrupts main ENDP END main ; Starts at main

Some programmers may prepare everything for INT 21h at once:

MOV AX, 4C00h ; replace the 00 with your error code in HEX

Linux 32-bit x86 Assembly:

; For NASM MOV AL, 1 ; Function 1: exit() MOV EBX, 0 ; Return code INT 80h ; # Passes control to interrupt vector # invokes system call—in this case system call # number 1 with argument 0

# For GAS .text

.global _start

_start: movl $1, %eax # System call number 1: exit() movl $0, %ebx # Exits with exit status 0 int $0x80 # Passes control to interrupt vector # invokes system call—in this case system call # number 1 with argument 0

Linux 64-bit x86 64 Assembly: for FASM

OS X 64-bit x86 64 Assembly: for NASM

Windows

On Windows, a program can terminate itself by calling either the ExitProcess function or the RtlExitUserProcess function.

See also

References

External links exit: terminate a process – System Interfaces Reference, The Single UNIX Specification, Version 5 from The Open Group C++ reference for std::exit

Worked examples

Example 1 — a first encounter with Exit (system call)

Start with the simplest possible case. Write down what Exit (system call) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Exit (system call) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Exit (system call) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Exit (system call)

In research
Exit (system call) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Exit (system call) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Exit (system call) is common in secondary-school and first-year university syllabi. It links to neighbouring topics C standard library, POSIX, Process (computing), so understanding it makes those chapters shorter.
In everyday life
Look for Exit (system call) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Exit (system call)” →

How to study Exit (system call) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Exit (system call) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Exit (system call) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Exit (system call) in simple terms?

On many computer operating systems, a computer process terminates its execution by making an exit system call. More generally, an exit in a multithreading environment means that a thread of execution has stopped running.

Why does Exit (system call) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Exit (system call)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Exit (system call).

Tags

  • C standard library
  • POSIX
  • Process (computing)
  • Subroutines

Keep exploring