abort系统函数应用实例

函数名: 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那样不做任何清理工作就退出,而是在完成所有的清理工作后才退出程序。

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值