---恢复内容开始---

代码1:(带参main函数)

#include<stdio.h>
int main(int number, char *parameter[])
{
int i = ;
printf("number is : %d \n", number);
for(i=; i<number; i++)
{
printf("parameter[%d] is : %s \n", i, parameter[i]); }
if(number!=)
printf("not 3!!!\n");
}

运行:

yisheng@yisheng-v-m:~/xtbc$ gcc main.c
yisheng@yisheng-v-m:~/xtbc$ ./a.out
number is :
parameter[] is : ./a.out
not !!!
yisheng@yisheng-v-m:~/xtbc$ ./a.out
number is :
parameter[] is : ./a.out
parameter[] is :
parameter[] is :
parameter[] is :
not !!!

代码2:excel函数:

#include<stdio.h>
#include<unistd.h> int main()
{
int ret;
ret=execl("./main","main","",NULL); if(ret<)
perror("execl");
  printf("excel over\n"); }

运行程序:

yisheng@yisheng-v-m:~/xtbc$ gcc main.c -o ./main  //要先生成可执行的./main
yisheng@yisheng-v-m:~/xtbc$ gcc .c
yisheng@yisheng-v-m:~/xtbc$ ./a.out
number is :
parameter[] is : main
parameter[] is :
not !!!

在这种情况之下,不能够输出后面的“excle over”内容,无法得知进程是否完成,可以改进一下程序,利用fork()创建子进程:

#include<stdio.h>
#include<unistd.h>
#include<wait.h>
#include<stdlib.h>
int main()
{
int ret;
int pid;
pid=fork();
if(pid==)
{
ret=execl("./main","main","",NULL); if(ret<)
{
perror("execl"); }
exit();
}
if(pid>)
{
wait(NULL);
printf("excel over\n");
}
return ;
}

结果为:

yisheng@yisheng-v-m:~/xtbc$ ./a.out //已经存在./main
number is :
parameter[] is : main
parameter[] is :
not !!!
excel over

最新文章

  1. VQuery选择器
  2. C 记录
  3. C和C++混合编程
  4. centos6.7下编译安装lnmp
  5. swfupdate flash上传工具
  6. C++例题1:输出可打印字符
  7. 2013 长沙网络赛 B 题 Bizarre Routine
  8. 自定义DB连接池实现
  9. POJ 3621 Sightseeing Cows [最优比率环]
  10. Chapter 5 Blood Type——21
  11. Ubuntu16.04多个版本GCC编译器的安装和切换
  12. Netty 超时机制及心跳程序实现
  13. OneZero产品视频
  14. LaTeX使用学习
  15. gispro试用版账户注册
  16. 阿里云-centos7.2-LNMP-编译安装-记录
  17. hexo d 报错‘fatal: could not read Username for &#39;https://github.com&#39;: No error’
  18. Python Threading多线程简单例子
  19. NSObject之二
  20. 洛咕 P2468 [SDOI2010]粟粟的书架

热门文章

  1. MYSQL与TiDB的执行计划
  2. JS StartMove源码-简单运动框架
  3. MySql:SELECT 语句(二)排序 ORDER BY 的使用
  4. Python爬虫中文小说网点查找小说并且保存到txt(含中文乱码处理方法)
  5. 请求不同域的数据方法:requests Jsonp cors
  6. jQuery之必会增删改查Dom操作
  7. Array.prototype.push.apply(a,b)和Array.prototype.slice.call(arguments)
  8. Nginx搭建
  9. 中间件之Kafka
  10. lambda正则化参数的大小影响