void abort(void)
原型位于 stdlib.h, process.h
适用于 UNIX 系统,在 ANSI C 中有定义
该函数将终止信息 “Abnormal program termination" 写入 stderr 中, 并通过调用带有终止码 3 的
_exit 来终止程序。
abort 将把终止码 3 返回给父进程 或 DOS
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf(" Calling abort()/n");
abort();
/* this is never reached */
printf(" You'll never see this/n");
return 0;
}
运行结果如图:
_exit 终止程序
void _exit(int status)
原型位于 stdlib.h, process.h
适用于 UNIX 系统,在 ANSI C 中有定义
_eixt 终止调用进程, 但不关闭文件, 不清除输出缓存,也不 调用出口函数。
调用进程 时用 status 作为出口状态,一般来说, 0 表示正常出口, 非 0 值表示有错误发生。
没有返回值
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf(" Calling abort()/n");
_exit(3);
/* this is never reached */
printf(" You'll never see this/n");
return 0;
}
结果如图: