- 论坛徽章:
- 0
|
本帖最后由 liuaiping0205 于 2012-12-26 20:33 编辑
回复 5# crazy_snail
这种方法可以,
file1.c- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <dlfcn.h>
- int
- main ()
- {
- pid_t fd;
- fd = fork ();
- char *argv[] = {"hello"};
- if (fd < 0 ){
- printf ("fork error!\n");
- return 0;
- }
- else if (0 == fd) {
- if (execl ("./file",*argv,NULL) < 0) {
- printf ("execl error\n");
- return 0;
- }
- }
- else {
- wait (NULL);
- }
- return 0;
- }
复制代码 file.c ---编译成可执行文件“file”- #include <stdio.h>
- [code]int
- main (int argc,char *argv[])
- {
- printf ("argc = %d,argv[] = %s\n",argc,*argv);
-
- return 0;
- }
复制代码- #gcc file1.c -o file1
- #./file1
- 结果:
- argc = 1,argvi[] = hello
复制代码 |
|