- #include <stdio.h>
-
#include <unistd.h>
-
-
int main(int argc, char * argv[])
-
{
-
int i;
-
-
if(argc <= 1)
-
{
-
printf("no program need to execute!\n");
-
return -1;
-
}
-
for(i=1;i<argc;i++)
-
{
-
if(0 == fork())
-
{
-
printf("executing %s.......\n", argv[i]);
-
execlp(argv[i], argv[i], (char *)NULL);
-
}
-
}
-
return 0;
-
}
运行结果:
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
阅读(1327) | 评论(0) | 转发(0) |