Chinaunix首页 | 论坛 | 博客
  • 博客访问: 145723
  • 博文数量: 26
  • 博客积分: 645
  • 博客等级: 上士
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-05 15:00
文章分类

全部博文(26)

文章存档

2014年(1)

2013年(1)

2011年(22)

2010年(1)

2009年(1)

我的朋友

分类: LINUX

2011-06-28 22:02:16

  1. #include <stdio.h>
  2. #include <unistd.h>

  3. int main(int argc, char * argv[])
  4. {
  5.     int i;

  6.     if(argc <= 1)
  7.     {
  8.         printf("no program need to execute!\n");
  9.         return -1;
  10.     }
  11.     for(i=1;i<argc;i++)
  12.     {
  13.         if(0 == fork())
  14.         {
  15.             printf("executing %s.......\n", argv[i]);
  16.             execlp(argv[i], argv[i], (char *)NULL);
  17.         }
  18.     }
  19.     return 0;
  20. }

运行结果:
lisong@lisong:~/code/experiment/proc/exec$ ./callexec
no program need to execute!
lisong@lisong:~/code/experiment/proc/exec$ ./callexec /usr/share/touchpad-indicator/touchpad-indicator.py
executing /usr/share/touchpad-indicator/touchpad-indicator.py.......
lisong@lisong:~/code/experiment/proc/exec$ ps
  PID TTY          TIME CMD
 1552 pts/0    00:00:01 bash
 2138 pts/0    00:00:00 touchpad-indica
 2155 pts/0    00:00:00 python
 2205 pts/0    00:00:00 ps
lisong@lisong:~/code/experiment/proc/exec$ kill -9 2155
lisong@lisong:~/code/experiment/proc/exec$ ps
  PID TTY          TIME CMD
 1552 pts/0    00:00:01 bash
 2208 pts/0    00:00:00 ps
lisong@lisong:~/code/experiment/proc/exec$ ./callexec /usr/share/touchpad-indicator/touchpad-indicator.py /home/lisong/下载/linuxqq_v1.0.2_i386/qq
executing /home/lisong/下载/linuxqq_v1.0.2_i386/qq.......
executing /usr/share/touchpad-indicator/touchpad-indicator.py.......
lisong@lisong:~/code/experiment/proc/exec$ [22:06:22][TLOG][warn]res_db: error message-> no such table: res_db_file

(qq:2211): GdkPixbuf-CRITICAL **: gdk_pixbuf_add_alpha: assertion `GDK_IS_PIXBUF (pixbuf)' failed

(qq:2211): GdkPixbuf-CRITICAL **: gdk_pixbuf_copy_area: assertion `src_pixbuf != NULL' failed

第三次执行两个应用程序时 touchpad和 qq确实执行了,只可惜 ubuntu 中qq似乎不能从shell执行 ,因此打印一堆错误而自动结束。./callexec
阅读(1291) | 评论(0) | 转发(0) |
0

上一篇:main函数参数

下一篇:signal and wait

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