728x90

eixt()


#include <stdlib.h>
void exit (int status);

C library 종료 단계
1. atexit(), on_exit() 등록함수를 역순으로 출력
2. std I/O stream flush
3. tmpfile()로 만든 임시 파일 삭제
4. _exit() 호출

#include <unistd.h>
void _exit (int status);

사용하지 않는 자원 정리
allocated memory, opend file,, system V semaphore 등
kernel은 process를 제거한 다음 parent에게 통보함

application은 _exit()를 직접 호출할 수는 있지만 의미없다. vfork() 사용자는 fork 이후 exit()대신 _exit()호출해야 함.


atexit()

#include <stdlib.h>
int atexit (void (*function) (void));

주의 : parameter, return이 없다.
POSIX에서는 ATEXIT_MAX까지 함수 등록을 지원해야 하며 최소 32가 되어야 한다.
sysconf()와 _SC_ATEXIT_MAX로 정확한 값을 알 수 있다.

long atexit_max;
atexit_max = sysconf(_SC_ATEXIT_MAX);
printf("atexit_max = %ld\n", atexit_max);




on_exit()

#include <stdlib.h>
int on_exit (void (*function)(int, void *), void *arg);

parameter를 허용함
주의 : 솔라리스에서는 더이상 이 함수를 지원하지 않는다.

void my_function(int status, void *arg);


SIGCHLD
child process가 죽으면 kernel이 parent에게 통보함
signal(), sigaction()을 이용하여 처리.

728x90

'Programming > linux왕초보' 카테고리의 다른 글

[ubuntu] change default shell  (0) 2016.03.22
GDB를 사용한 CORE 파일의 분석  (0) 2016.02.05
kernel make menuconfig error  (0) 2016.01.21
Caching your GitHub password in Git  (0) 2016.01.08
Serial ports usage on Linux  (0) 2016.01.08
fork  (0) 2015.05.26
Linux SSD 최적화  (0) 2015.04.17
fflush, fileno  (0) 2015.04.07
[Linux] stream write  (0) 2015.03.26
linux filesystem 사용 용량 확인  (0) 2015.03.18

+ Recent posts