函数名: abort
功 能: 异常终止一个进程
描述:abort()函数首先解除进程对SIGABRT信号的阻止,然后向调用进程发送该信号。abort()函数会导致进程的异常终止除非SIGABRT信号被捕捉并且信号处理句柄没有返回。
abort()函数导致所有的流被关闭和冲洗。
abort()函数没有返回值:void abort(void);
用 法: void abort(void);
程序例:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("hello word\n");
abort();
printf("call abort over\n");
return 0;
}
Makefile
CXX=g++
CFLAGS=-O3 -Wall -fmessage-length=0 -fPIC -DARCH_x86
OBJS=abort.o
LIBS+=
TARGET= Tabort
$(TARGET):$(OBJS)
$(CXX) -o $(TARGET) $(OBJS) $(CFLAGS) $(LIBS)
chmod 6755 $(TARGET)
all:$(TARGET)
install: all
chmod 6755 $(TARGET)
clean:
rm -f $(OBJS) $(TARGET)
运行结果
[root@localhost abort]# make clean;make
make: Warning: File `Makefile' has modification time 109 s in the future
rm -f abort.o Tabort
make: warning: Clock skew detected. Your build may be incomplete.
make: Warning: File `Makefile' has modification time 109 s in the future
cc -O3 -Wall -fmessage-length=0 -fPIC -DARCH_x86 -c -o abort.o abort.c
g++ -o Tabort abort.o -O3 -Wall -fmessage-length=0 -fPIC -DARCH_x86
chmod 6755 Tabort
make: warning: Clock skew detected. Your build may be incomplete.
[root@localhost abort]# ll
total 24
-rwxr--r-- 1 root root 145 Nov 26 11:26 abort.c
-rw-r--r-- 1 root root 1728 Nov 26 11:32 abort.o
-rwxr--r-- 1 root root 264 Nov 26 2015 Makefile
-rwsr-sr-x 1 root root 8562 Nov 26 11:32 Tabort
[root@localhost abort]# ./Tabort
hello word
Aborted
exit()用来正常终结目前进程的执行,并把参数 status 返回给父进程,
而进程所有的缓冲区数据会自动写回并关闭未关闭的文件。
它并不像abort那样不做任何清理工作就退出,而是在完成所有的清理工作后才退出程序。