Chinaunix首页 | 论坛 | 博客
  • 博客访问: 629363
  • 博文数量: 85
  • 博客积分: 1306
  • 博客等级: 中尉
  • 技术积分: 990
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-28 11:23
个人简介

嵌入式视频行业。

文章分类

全部博文(85)

文章存档

2015年(7)

2014年(5)

2013年(41)

2012年(11)

2011年(1)

2010年(3)

2008年(17)

分类: LINUX

2013-05-13 15:44:36

转载地址:http://blog.csdn.net/hjs1122/article/details/65751...

 

先写一个被调用的函数

[c-sharp] view plaincopyprint?

  1. #include 
  2. #include 
  3. #include 
  4. #include 
  5. int main()  
  6. {  
  7. printf("Return 10./n");  
  8. return 10;  
  9. }  

==================================
编译后生成一个"rt"的可执行文件
运行结果
==================================
Return 10.
==================================
再写一个调用system的程序
==================================

[c-sharp] view plaincopyprint?

  1. #include 
  2. #include 
  3. #include 
  4. #include 
  5. int main()  
  6. {  
  7.     pid_t          status;  
  8. int            errno = 0;  
  9.     status = system("./rt");  
  10.     printf("wifexited(status):%d/n", WIFEXITED(status));  
  11.     printf("WEXITSTATUS(status):%d/n", WEXITSTATUS(status));  
  12. if (status == -1) {  
  13.         printf("system error!");  
  14.     }  
  15. if (WIFEXITED(status)) {  
  16.         printf("cp exit normal![%d]/n", errno);  
  17.         printf("exit staus = [%X]/n", WEXITSTATUS(status));  
  18.     } else
  19.         printf("cp exit illegal![%d]/n", errno);  
  20. }  

==================================
编译后运行结果
==================================
Return 10.
wifexited(status):1
WEXITSTATUS(status):10
cp exit normal![0]
exit staus = [A]
==================================
可以看到:
WEXITSTATUS(status)可以得到调用程序的返回值。

阅读(2677) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~