Tue .19 Sep 2019
TR | RU | UK | KK | BE |

exit (system call)

exit system call in linux
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

Contents

  • 1 How it works
    • 11 Clean up
    • 12 Orphans and zombies
  • 2 Examples
  • 3 Windows
  • 4 See also
  • 5 External links

How it worksedit

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 error or signal eg, 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 eg, 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 eg, OpenVMS use even-numbered values for success and odd values for errors Still other systems eg, IBM z/OS and its predecessors use ranges of integer values to indicate success, warning, and error completion results

Clean upedit

The exit operation typically performs clean-up 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 clean-up 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 zombiesedit

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 process table in a consistent state

Examplesedit

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

C:
#include <stdlibh>int mainvoid
C++:#include <cstdlib>int main

COBOL:

IDENTIFICATION DIVISION PROGRAM-ID SUCCESS-PROGRAMPROCEDURE DIVISION MAIN MOVE ZERO TO RETURN-CODE END PROGRAM

Java:

public class Success

PC DOS Batch file:

exit 0

Perl:

#!/bin/perlexit;

PHP:

<phpexit0;>

Python:

#!/usr/bin/pythonimport syssysexit0

Unix shell:

exit 0

Pascal:

program pr1;begin exit0;end;

PC DOS Assembly:

; For MASM/TASMMODEL SMALLSTACKCODEmain PROC NEARMOV AH, 4Ch ; Service 4Ch - Terminate with Error CodeMOV AL, 0 ; Error codeINT 21h ; Interrupt 21h - DOS General Interruptsmain ENDPEND 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 NASMMOV AL, 1 ; Function 1:exitMOV EBX, 0 ; Return codeINT 80h ; The only interrupt Linux uses!# For GAStextglobal _start_start:movl $1, %eax# System call number 1:exitmovl $0, %ebx# Exits with exit status 0int $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

format ELF64 executable 3entry startsegment readable executablestart: ; STUFF ; exiting mov eax, 60; sys_exit syscall number:60 xor edi, edi ; set exit status to 0 `xor edi, edi` is equal to `mov edi, 0`syscall; call it

Windowsedit

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

See alsoedit

External linksedit

  • exit: terminate a process – System Interfaces Reference, The Single UNIX® Specification, Issue 7 from The Open Group
  • C++ reference for std::exit

exit system call in linux


exit (system call) Information about

exit (system call)


  • user icon

    exit (system call) beatiful post thanks!

    29.10.2014


exit (system call)
exit (system call)
exit (system call) viewing the topic.
exit (system call) what, exit (system call) who, exit (system call) explanation

There are excerpts from wikipedia on this article and video

Random Posts

Book

Book

A book is a set of written, printed, illustrated, or blank sheets, made of ink, paper, parchment, or...
Boston Renegades

Boston Renegades

Boston Renegades was an American women’s soccer team, founded in 2003 The team was a member of the U...
Sa Caleta Phoenician Settlement

Sa Caleta Phoenician Settlement

Sa Caleta Phoenician Settlement can be found on a rocky headland about 10 kilometers west of Ibiza T...
Bodybuilding.com

Bodybuilding.com

Bodybuildingcom is an American online retailer based in Boise, Idaho, specializing in dietary supple...