Chinaunix首页 | 论坛 | 博客
  • 博客访问: 953555
  • 博文数量: 113
  • 博客积分: 7235
  • 博客等级: 少将
  • 技术积分: 2101
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-14 11:24
文章分类

全部博文(113)

文章存档

2013年(7)

2012年(5)

2011年(6)

2010年(8)

2009年(15)

2008年(72)

分类: LINUX

2008-07-14 12:15:26

进程终止:

6)exit()函数

 头文件  #include  #include
 功能  正常终止进程 终止进程执行 
 原型  void exit(int status) void _exit(int status) 
 传入数值  整数 status  整数 status
 注

 exit()用来正常终止目前进程的

 执行,并把参数status返回给父

 进程,而进程所有的缓冲数据会

 自动写回并关闭未关闭的文件

_exit()哟年来立刻终止目前进程

的执行,并把参数status返回给父

进程,并关闭未关闭的文件,但不处

理标准I/O缓冲区 

例:

#include

#include

#include

int main()

{

   pid_t result;

   result=fork();

   if(result==-1)

  {

     perror("创建进程失败!");

     esit(0);

  }

  else if(result==0)

  {

     printf("测试终止进程函数_exit()!\n");

     printf("这一行用缓存!");

     _exit(0);

  }

  else

  { 

     printf("测试终止进程函数exit()!\n");

     printf("这一行用缓存!");

     exit(0);

  }

  return 0;

}

阅读(1278) | 评论(0) | 转发(0) |
0

上一篇:学习makefile感想

下一篇:对#!bin/sh的认识

给主人留下些什么吧!~~